Skip to content

Commit d10bac9

Browse files
committed
first working analyzer: prior to extra features
1 parent 79ab484 commit d10bac9

2 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Beginning Ruby - Second Edition
2+
# Exercise from Chapter 4 - Developing your first Ruby Application
3+
# Sam Gerber
4+
5+
# Required basic features:
6+
# * character count
7+
# * character count (excluding spaces)
8+
# * line count
9+
# * word count
10+
# * sentence count
11+
# * paragraph count
12+
# * average number of words per sentence
13+
# * average number of sentences in a paragraph
14+
15+
lines = File.readlines("lib/text.txt")
16+
line_count = lines.size
17+
text = lines.join
18+
19+
total_characters = text.length
20+
21+
total_characters_nospaces = text.gsub(/\s+/, '').length
22+
23+
word_count = text.split.length
24+
25+
sentence_count = text.split(/\.|\?|!/).length
26+
27+
paragraph_count = text.split(/\n\n/).length
28+
29+
average_words_per_sentence = word_count / sentence_count
30+
31+
average_sentences_per_paragraph = sentence_count / paragraph_count
32+
33+
puts "#{line_count} lines"
34+
puts "#{total_characters} characters"
35+
puts "#{total_characters_nospaces} characters (excluding spaces)"
36+
puts "#{word_count} words"
37+
puts "#{sentence_count} sentences"
38+
puts "#{paragraph_count} paragraphs"
39+
puts "#{average_words_per_sentence} words per sentence (on average)"
40+
puts "#{average_sentences_per_paragraph} sentences per paragraph (on average)"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Among other public buildings in a certain town, which for many
2+
reasons it will be prudent to refrain from mentioning, and to
3+
which I will assign no fictitious name, there is one anciently
4+
common to most towns, great or small: to wit, a workhouse; and
5+
in this workhouse was born; on a day and date which I need not
6+
trouble myself to repeat, inasmuch as it can be of no possible
7+
consequence to the reader, in this stage of the business at all
8+
events; the item of mortality whose name is prefixed to the head
9+
of this chapter.
10+
11+
For a long time after it was ushered into this world of sorrow
12+
and trouble, by the parish surgeon, it remained a matter of
13+
considerable doubt whether the child would survive to bear any
14+
name at all; in which case it is somewhat more than probable that
15+
these memoirs would never have appeared; or, if they had, that
16+
being comprised within a couple of pages, they would have
17+
possessed the inestimable merit of being the most concise and
18+
faithful specimen of biography, extant in the literature of any
19+
age or country.
20+
21+
Although I am not disposed to maintain that the being born in a
22+
workhouse, is in itself the most fortunate and enviable
23+
circumstance that can possibly befall a human being, I do mean to
24+
say that in this particular instance, it was the best thing for
25+
Oliver Twist that could by possibility have occurred. The fact
26+
is, that there was considerable difficulty in inducing Oliver to
27+
take upon himself the office of respiration,--a troublesome
28+
practice, but one which custom has rendered necessary to our easy
29+
existence; and for some time he lay gasping on a little flock
30+
mattress, rather unequally poised between this world and the
31+
next: the balance being decidedly in favour of the latter. Now,
32+
if, during this brief period, Oliver had been surrounded by
33+
careful grandmothers, anxious aunts, experienced nurses, and
34+
doctors of profound wisdom, he would most inevitably and
35+
indubitably have been killed in no time. There being nobody by,
36+
however, but a pauper old woman, who was rendered rather misty by
37+
an unwonted allowance of beer; and a parish surgeon who did such
38+
matters by contract; Oliver and Nature fought out the point
39+
between them. The result was, that, after a few struggles,
40+
Oliver breathed, sneezed, and proceeded to advertise to the
41+
inmates of the workhouse the fact of a new burden having been
42+
imposed upon the parish, by setting up as loud a cry as could
43+
reasonably have been expected from a male infant who had not been
44+
possessed of that very useful appendage, a voice, for a much
45+
longer space of time than three minutes and a quarter.
46+
47+
As Oliver gave this first proof of the free and proper action of
48+
his lungs, the patchwork coverlet which was carelessly flung over
49+
the iron bedstead, rustled; the pale face of a young woman was
50+
raised feebly from the pillow; and a faint voice imperfectly
51+
articulated the words, 'Let me see the child, and die.'
52+
53+
The surgeon had been sitting with his face turned towards the
54+
fire: giving the palms of his hands a warm and a rub
55+
alternately. As the young woman spoke, he rose, and advancing to
56+
the bed's head, said, with more kindness than might have been
57+
expected of him:
58+
59+
'Oh, you must not talk about dying yet.'
60+
61+
'Lor bless her dear heart, no!' interposed the nurse, hastily
62+
depositing in her pocket a green glass bottle, the contents of
63+
which she had been tasting in a corner with evident satisfaction.
64+
65+
'Lor bless her dear heart, when she has lived as long as I have,
66+
sir, and had thirteen children of her own, and all on 'em dead
67+
except two, and them in the wurkus with me, she'll know better
68+
than to take on in that way, bless her dear heart! Think what it
69+
is to be a mother, there's a dear young lamb do.'
70+
71+
Apparently this consolatory perspective of a mother's prospects
72+
failed in producing its due effect. The patient shook her head,
73+
and stretched out her hand towards the child.
74+
75+
The surgeon deposited it in her arms. She imprinted her cold
76+
white lips passionately on its forehead; passed her hands over
77+
her face; gazed wildly round; shuddered; fell back--and died.
78+
They chafed her breast, hands, and temples; but the blood had
79+
stopped forever. They talked of hope and comfort. They had been
80+
strangers too long.
81+
82+
'It's all over, Mrs. Thingummy!' said the surgeon at last.
83+
84+
'Ah, poor dear, so it is!' said the nurse, picking up the cork of
85+
the green bottle, which had fallen out on the pillow, as she
86+
stooped to take up the child. 'Poor dear!'
87+
88+
'You needn't mind sending up to me, if the child cries, nurse,'
89+
said the surgeon, putting on his gloves with great deliberation.
90+
'It's very likely it WILL be troublesome. Give it a little gruel
91+
if it is.' He put on his hat, and, pausing by the bed-side on
92+
his way to the door, added, 'She was a good-looking girl, too;
93+
where did she come from?'
94+
95+
'She was brought here last night,' replied the old woman, 'by the
96+
overseer's order. She was found lying in the street. She had
97+
walked some distance, for her shoes were worn to pieces; but
98+
where she came from, or where she was going to, nobody knows.'
99+
100+
The surgeon leaned over the body, and raised the left hand. 'The
101+
old story,' he said, shaking his head: 'no wedding-ring, I see.
102+
Ah! Good-night!'
103+
104+
The medical gentleman walked away to dinner; and the nurse,
105+
having once more applied herself to the green bottle, sat down on
106+
a low chair before the fire, and proceeded to dress the infant.
107+
108+
What an excellent example of the power of dress, young Oliver
109+
Twist was! Wrapped in the blanket which had hitherto formed his
110+
only covering, he might have been the child of a nobleman or a
111+
beggar; it would have been hard for the haughtiest stranger to
112+
have assigned him his proper station in society. But now that he
113+
was enveloped in the old calico robes which had grown yellow in
114+
the same service, he was badged and ticketed, and fell into his
115+
place at once--a parish child--the orphan of a workhouse--the
116+
humble, half-starved drudge--to be cuffed and buffeted through
117+
the world--despised by all, and pitied by none.
118+
119+
Oliver cried lustily. If he could have known that he was an
120+
orphan, left to the tender mercies of church-wardens and
121+
overseers, perhaps he would have cried the louder.

0 commit comments

Comments
 (0)