Class: ONIX::ElementParser
- Inherits:
-
Object
- Object
- ONIX::ElementParser
- Defined in:
- lib/onix/subset.rb
Overview
for class DSL
Instance Attribute Summary collapse
-
#cardinality ⇒ Object
Returns the value of attribute cardinality.
-
#klass_name ⇒ Object
Returns the value of attribute klass_name.
-
#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
- #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
- #shortcut ⇒ Object
- #to_instance ⇒ Object
- #to_sym ⇒ Object
- #underscore_name ⇒ String
Constructor Details
#initialize(name, type, options = {}) ⇒ ElementParser
Returns a new instance of ElementParser.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/onix/subset.rb', line 151 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] @shortcut = [:shortcut] @cardinality = [:cardinality] @cardinality = nil if @cardinality == 0..n # no need to check if 0..n if [:klass] @klass_name = [:klass] else @klass_name = name end end |
Instance Attribute Details
#cardinality ⇒ Object
Returns the value of attribute cardinality.
122 123 124 |
# File 'lib/onix/subset.rb', line 122 def cardinality @cardinality end |
#klass_name ⇒ Object
Returns the value of attribute klass_name.
122 123 124 |
# File 'lib/onix/subset.rb', line 122 def klass_name @klass_name end |
#name ⇒ Object
Returns the value of attribute name.
122 123 124 |
# File 'lib/onix/subset.rb', line 122 def name @name end |
#short ⇒ Object
Returns the value of attribute short.
122 123 124 |
# File 'lib/onix/subset.rb', line 122 def short @short end |
#type ⇒ Object
Returns the value of attribute type.
122 123 124 |
# File 'lib/onix/subset.rb', line 122 def type @type end |
Class Method Details
.inflectors ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/onix/subset.rb', line 124 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
#class_name ⇒ Object
200 201 202 |
# File 'lib/onix/subset.rb', line 200 def class_name @klass_name end |
#is_array? ⇒ Boolean
191 192 193 |
# File 'lib/onix/subset.rb', line 191 def is_array? @array end |
#parse_lambda(v) ⇒ Object
183 184 185 |
# File 'lib/onix/subset.rb', line 183 def parse_lambda(v) @parse_lambda ? @parse_lambda.call(v) : v end |
#serialize_lambda(v) ⇒ Object
187 188 189 |
# File 'lib/onix/subset.rb', line 187 def serialize_lambda(v) @serialize_lambda ? @serialize_lambda.call(v) : v end |
#shortcut ⇒ Object
179 180 181 |
# File 'lib/onix/subset.rb', line 179 def shortcut @shortcut end |
#to_instance ⇒ Object
208 209 210 |
# File 'lib/onix/subset.rb', line 208 def to_instance @instance ||= "@" + self.underscore_name end |
#to_sym ⇒ Object
204 205 206 |
# File 'lib/onix/subset.rb', line 204 def to_sym @sym ||= self.underscore_name.to_sym end |
#underscore_name ⇒ String
196 197 198 |
# File 'lib/onix/subset.rb', line 196 def underscore_name @underscore_name ||= (@array && @pluralize) ? pluralize(underscore(@name)) : underscore(@name) end |