Module: Dphil::MetricalData
- Defined in:
- lib/dphil/metrical_data.rb
Overview
Metrical Data structure imported and parsed from “metrical_data” module at: github.com/shreevatsa/sanskrit
Defined Under Namespace
Class Attribute Summary collapse
-
.all ⇒ Object
readonly
Returns the value of attribute all.
-
.meters ⇒ Object
readonly
Returns the value of attribute meters.
-
.patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
.regexes ⇒ Object
readonly
Returns the value of attribute regexes.
-
.version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.load_data! ⇒ Object
This loads and processes the data into the module.
Class Attribute Details
.all ⇒ Object (readonly)
Returns the value of attribute all.
14 15 16 |
# File 'lib/dphil/metrical_data.rb', line 14 def all @all end |
.meters ⇒ Object (readonly)
Returns the value of attribute meters.
14 15 16 |
# File 'lib/dphil/metrical_data.rb', line 14 def meters @meters end |
.patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
14 15 16 |
# File 'lib/dphil/metrical_data.rb', line 14 def patterns @patterns end |
.regexes ⇒ Object (readonly)
Returns the value of attribute regexes.
14 15 16 |
# File 'lib/dphil/metrical_data.rb', line 14 def regexes @regexes end |
.version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/dphil/metrical_data.rb', line 14 def version @version end |
Class Method Details
.load_data! ⇒ Object
This loads and processes the data into the module.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dphil/metrical_data.rb', line 20 def self.load_data! yml_data = Psych.load_file(File.join(GEM_ROOT, "vendor", "metrical_data.yml")) @version = yml_data["commit"].deep_freeze # Hash of meters with names as keys and patterns as values meters_h = yml_data["meters"].each_with_object({}) do |(name, patterns), h| h[Transliterate.unicode_downcase(name)] = patterns end @meters = IHash.new(meters_h) # Hash of meters with patterns for keys and names/padas as values patterns_h = yml_data["patterns"].each_with_object({}) do |(type, patterns), type_h| type_h[type.to_sym] = (patterns.each_with_object({}) do |(pattern, meters), pattern_h| pattern_h[pattern] = meters.each_with_object({}) do |(name, value), name_h| name_h[Transliterate.unicode_downcase(name)] = value end end).sort_by { |(k, _)| k.to_s.length }.reverse.to_h end @patterns = IHashM.new(patterns_h) # Hash of meters with regular expressions for keys and names/padas as values regexes_h = yml_data["regexes"].each_with_object({}) do |(type, patterns), type_h| type_h[type.to_sym] = (patterns.each_with_object({}) do |(pattern, meters), pattern_h| new_pattern = Regexp.new(pattern.source.gsub(/^\^|\$$/, "")) pattern_h[new_pattern] = meters.each_with_object({}) do |(name, value), name_h| name_h[Transliterate.unicode_downcase(name)] = value end end).sort_by { |(k, _)| k.to_s.length }.reverse.to_h end @regexes = IHashM.new(regexes_h) @all = IHashM.new(version: version, meters: meters, patterns: patterns, regexes: regexes) self end |