Class: ONIX::ElementParser
- Inherits:
-
Object
- Object
- ONIX::ElementParser
- Defined in:
- lib/onix/subset.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#short ⇒ Object
Returns the value of attribute short.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #_underscore_name ⇒ Object
- #class_name ⇒ Object
-
#initialize(name, type, options = {}) ⇒ ElementParser
constructor
A new instance of ElementParser.
- #is_array? ⇒ Boolean
- #parse_lambda(v) ⇒ Object
- #serialize_lambda(v) ⇒ Object
- #to_instance ⇒ Object
- #to_sym ⇒ Object
- #underscore_name ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ ElementParser
Returns a new instance of ElementParser.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/onix/subset.rb', line 82 def initialize(name, type, ={}) @name=name @type=type @pluralize=true @short = false @array=false @parse_lambda = nil @serialize_lambda = nil if [:array] @array=true end if [:pluralize]==false @pluralize=false end @parse_lambda=[:parse_lambda] @serialize_lambda=[:serialize_lambda] if [:klass] @klass_name=[:klass] else @klass_name=name end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
53 54 55 |
# File 'lib/onix/subset.rb', line 53 def name @name end |
#short ⇒ Object
Returns the value of attribute short.
53 54 55 |
# File 'lib/onix/subset.rb', line 53 def short @short end |
#type ⇒ Object
Returns the value of attribute type.
53 54 55 |
# File 'lib/onix/subset.rb', line 53 def type @type end |
Class Method Details
.inflectors ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/onix/subset.rb', line 55 def self.inflectors [['ox', 'oxes'], ['us', 'uses'], ['', 's'], ['ero', 'eroes'], ['rf', 'rves'], ['af', 'aves'], ['ero', 'eroes'], ['man', 'men'], ['ch', 'ches'], ['sh', 'shes'], ['ss', 'sses'], ['ta', 'tum'], ['ia', 'ium'], ['ra', 'rum'], ['ay', 'ays'], ['ey', 'eys'], ['oy', 'oys'], ['uy', 'uys'], ['y', 'ies'], ['x', 'xes'], ['lf', 'lves'], ['ffe', 'ffes'], ['afe', 'aves'], ['ouse', 'ouses']] end |
Instance Method Details
#_underscore_name ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/onix/subset.rb', line 127 def _underscore_name if @array and @pluralize pluralize(underscore(@name)) else underscore(@name) end end |
#class_name ⇒ Object
139 140 141 |
# File 'lib/onix/subset.rb', line 139 def class_name @klass_name end |
#is_array? ⇒ Boolean
123 124 125 |
# File 'lib/onix/subset.rb', line 123 def is_array? @array end |
#parse_lambda(v) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/onix/subset.rb', line 107 def parse_lambda(v) if @parse_lambda @parse_lambda.call(v) else v end end |
#serialize_lambda(v) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/onix/subset.rb', line 115 def serialize_lambda(v) if @serialize_lambda @serialize_lambda.call(v) else v end end |
#to_instance ⇒ Object
147 148 149 |
# File 'lib/onix/subset.rb', line 147 def to_instance @instance||="@"+self.underscore_name end |
#to_sym ⇒ Object
143 144 145 |
# File 'lib/onix/subset.rb', line 143 def to_sym @sym||=self.underscore_name.to_sym end |
#underscore_name ⇒ Object
135 136 137 |
# File 'lib/onix/subset.rb', line 135 def underscore_name @underscore_name||=_underscore_name end |