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.
12 13 14 15 16 17 |
# File 'lib/paxmex/schema/field.rb', line 12 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.
10 11 12 |
# File 'lib/paxmex/schema/field.rb', line 10 def final @final end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/paxmex/schema/field.rb', line 10 def name @name end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
10 11 12 |
# File 'lib/paxmex/schema/field.rb', line 10 def start @start end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/paxmex/schema/field.rb', line 10 def type @type end |
Instance Method Details
#parse(raw_value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/paxmex/schema/field.rb', line 19 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 parse_numeric(raw_value) 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 |