Class: Paxmex::Schema::Field
- Inherits:
-
Object
- Object
- Paxmex::Schema::Field
- Defined in:
- lib/paxmex/schema/field.rb
Constant Summary collapse
- DATE_PATTERN =
/^date\((.+)\)$/
- TIME_PATTERN =
/^time\((.+)\)$/
Instance Attribute Summary collapse
-
#final ⇒ Object
readonly
Returns the value of attribute final.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Field
constructor
A new instance of Field.
- #parse(raw_value) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Field
Returns a new instance of Field.
10 11 12 13 14 15 |
# File 'lib/paxmex/schema/field.rb', line 10 def initialize(opts = {}) @name = opts[:name] @start = opts[:start] @final = opts[:final] @type = opts[:type] || 'string' end |
Instance Attribute Details
#final ⇒ Object (readonly)
Returns the value of attribute final.
8 9 10 |
# File 'lib/paxmex/schema/field.rb', line 8 def final @final end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/paxmex/schema/field.rb', line 8 def name @name end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
8 9 10 |
# File 'lib/paxmex/schema/field.rb', line 8 def start @start end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/paxmex/schema/field.rb', line 8 def type @type end |
Instance Method Details
#parse(raw_value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/paxmex/schema/field.rb', line 17 def parse(raw_value) case type when 'string' then raw_value.rstrip when 'julian' then parse_julian_date(raw_value) rescue nil when 'date' then Date.strptime(raw_value, '%m%d%Y') rescue nil when 'numeric' then raw_value.strip.to_i when 'decimal' then parse_decimal(raw_value) when DATE_PATTERN then parse_date_pattern(raw_value) rescue nil when TIME_PATTERN then parse_time_pattern(raw_value) rescue nil else fail "Could not parse field type #{type}. Supported types: string, julian, date, numeric, decimal, date(format), time(format)" end end |