Class: ONIX::ElementParser

Inherits:
Object
  • Object
show all
Defined in:
lib/onix/subset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options={})
  @name=name
  @type=type
  @pluralize=true
  @short = false
  @array=false
  @parse_lambda = nil
  @serialize_lambda = nil
  if options[:array]
    @array=true
  end
  if options[:pluralize]==false
    @pluralize=false
  end

  @parse_lambda=options[:parse_lambda]
  @serialize_lambda=options[:serialize_lambda]

  if options[:klass]
    @klass_name=options[:klass]
  else
    @klass_name=name
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



53
54
55
# File 'lib/onix/subset.rb', line 53

def name
  @name
end

#shortObject

Returns the value of attribute short.



53
54
55
# File 'lib/onix/subset.rb', line 53

def short
  @short
end

#typeObject

Returns the value of attribute type.



53
54
55
# File 'lib/onix/subset.rb', line 53

def type
  @type
end

Class Method Details

.inflectorsObject



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_nameObject



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_nameObject



139
140
141
# File 'lib/onix/subset.rb', line 139

def class_name
  @klass_name
end

#is_array?Boolean

Returns:

  • (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_instanceObject



147
148
149
# File 'lib/onix/subset.rb', line 147

def to_instance
  @instance||="@"+self.underscore_name
end

#to_symObject



143
144
145
# File 'lib/onix/subset.rb', line 143

def to_sym
  @sym||=self.underscore_name.to_sym
end

#underscore_nameObject



135
136
137
# File 'lib/onix/subset.rb', line 135

def underscore_name
  @underscore_name||=_underscore_name
end