Module: Langue::Japanese::Attribute
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(object) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/langue/japanese/words/attribute.rb', line 7 def self.included(object) object.class_eval do include MorphemeFilter filter { |word, morphemes| word.empty? ? morphemes : morphemes[0..morphemes.index(word.key_morpheme)] } def self.has(*attrs) attrs.each do |attr| define_method("#{attr}?") do @attrs ||= {} @attrs[attr] = !!__send__("include_#{attr}?") unless @attrs.key?(attr) @attrs[attr] end end end end end |
Instance Method Details
#body ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/langue/japanese/words/attribute.rb', line 24 def body unless instance_variable_defined?(:@body) @body = if body_morphemes.empty? nil else morphemes = body_morphemes.dup last_morpheme = morphemes.pop morphemes.map(&:text).join + last_morpheme.root_form end end @body end |
#index(value = nil) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/langue/japanese/words/attribute.rb', line 39 def index(value = nil) if value super else each_with_index { |morpheme, index| return index if yield morpheme } nil end end |