Class: Langue::Japanese::Period
- Inherits:
-
Word
- Object
- Word
- Langue::Japanese::Period
- Defined in:
- lib/langue/japanese/words/period.rb
Constant Summary collapse
- COMMAS =
%w(, , 、)
- DOTS =
COMMAS + %w(. . 。 ・ ‥ …)
- MARKS =
%w(! ! ? ?)
Class Method Summary collapse
- .dot?(morphemes, index) ⇒ Boolean
- .mark?(morphemes, index) ⇒ Boolean
- .take(morphemes, index) ⇒ Object
- .take_dot(morphemes, index) ⇒ Object
- .take_mark(morphemes, index) ⇒ Object
Instance Method Summary collapse
Class Method Details
.dot?(morphemes, index) ⇒ Boolean
23 24 25 |
# File 'lib/langue/japanese/words/period.rb', line 23 def dot?(morphemes, index) morphemes.at(index) { |m| DOTS.include?(m.text) } end |
.mark?(morphemes, index) ⇒ Boolean
27 28 29 |
# File 'lib/langue/japanese/words/period.rb', line 27 def mark?(morphemes, index) morphemes.at(index) { |m| MARKS.include?(m.text) } end |
.take(morphemes, index) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/langue/japanese/words/period.rb', line 13 def take(morphemes, index) if dot?(morphemes, index) take_dot(morphemes, index) elsif mark?(morphemes, index) take_mark(morphemes, index) else 0 end end |
.take_dot(morphemes, index) ⇒ Object
31 32 33 34 35 |
# File 'lib/langue/japanese/words/period.rb', line 31 def take_dot(morphemes, index) size = 0 size += 1 while dot?(morphemes, index + size) size == 1 && COMMAS.include?(morphemes[index].text) ? 0 : size end |
.take_mark(morphemes, index) ⇒ Object
37 38 39 40 41 |
# File 'lib/langue/japanese/words/period.rb', line 37 def take_mark(morphemes, index) size = 0 size += 1 while mark?(morphemes, index + size) size end |
Instance Method Details
#exclamation? ⇒ Boolean
44 45 46 47 |
# File 'lib/langue/japanese/words/period.rb', line 44 def exclamation? @exclamation = !!(text =~ /[!!]/) unless instance_variable_defined?(:@exclamation) @exclamation end |
#question? ⇒ Boolean
49 50 51 52 |
# File 'lib/langue/japanese/words/period.rb', line 49 def question? @question = !!(text =~ /[??]/) unless instance_variable_defined?(:@question) @question end |