Class: Linguistics::Latin::Verb::LatinVerb

Inherits:
Object
  • Object
show all
Defined in:
lib/latinverb_serialization/hash.rb,
lib/latinverb_serialization/json.rb,
lib/latinverb_serialization/yaml.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.json_create(o) ⇒ Object



5
6
7
# File 'lib/latinverb_serialization/json.rb', line 5

def self.json_create(o)
  new(o)
end

Instance Method Details

#to_hashObject Also known as: to_h



5
6
7
8
9
# File 'lib/latinverb_serialization/hash.rb', line 5

def to_hash
  TENSE_BLOCK_NAMES.each_with_object(base_structure) do |tense_block_identifier, memo|
    memo[ts = (tense_block_identifier.to_sym)] = self.send(ts)
  end
end

#to_json(*a) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/latinverb_serialization/json.rb', line 9

def to_json(*a)
  json_hash = {'json_class' => self.class.name}

  # In the case that we're working with a regular verb, the only thing
  # we need to save is the original string, since everything can be
  # re-derived from it easily.
  unless self.irregular?
    # While this single string is sufficient to freeze and revivifty
    # the verb, it means that the JSON structure is rather vacuous.
    # Given this, the hash is enriched so that the JSON data is
    # useful.  Nevertheless, in the revivification process, only
    # 'orig_string' is used.
    %w{original_string classification stem}.each do |k|
      json_hash[k] = self.send k.to_sym
    end
    json_hash['tense_list' ]  = {}
    LatinVerb::TENSE_BLOCK_NAMES.each do |t|
      json_hash['tense_list'][t.to_s] = self.querent.send t.to_sym
    end
    json_hash['irregular']    = irregular?
    return json_hash.to_json(*a)
  end
end

#to_yamlObject Also known as: to_y



5
6
7
# File 'lib/latinverb_serialization/yaml.rb', line 5

def to_yaml
  to_hash.to_yaml
end