Class: Langue::Morpheme

Inherits:
Object
  • Object
show all
Defined in:
lib/langue/morpheme.rb

Constant Summary collapse

KEYS =
%w(
  text
  part_of_speech
  categories
  inflection
  inflection_type
  root_form
  yomi
  pronunciation
).map(&:to_sym)

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Morpheme

Returns a new instance of Morpheme.



14
15
16
# File 'lib/langue/morpheme.rb', line 14

def initialize(attrs)
  KEYS.each { |key| instance_variable_set("@#{key}", attrs[key]) }
end

Instance Method Details

#==(other_morpheme) ⇒ Object



20
21
22
23
# File 'lib/langue/morpheme.rb', line 20

def ==(other_morpheme)
  return false unless other_morpheme.is_a?(self.class)
  KEYS.all? { |key| self.__send__(key) == other_morpheme.__send__(key) }
end

#classified?(part_of_speech, *categories) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/langue/morpheme.rb', line 25

def classified?(part_of_speech, *categories)
  got = [@part_of_speech] + @categories
  expected = [part_of_speech] + categories
  expected.zip(got).all? { |pair| pair[0] == pair[1] }
end

#inflected?(inflection) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/langue/morpheme.rb', line 31

def inflected?(inflection)
  @inflection == inflection
end