Sha256: 8f3fce632f59aea33b839f50310b1557d42116badad34089472a848c17f8dccd

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module Qbxml::Types

  XML_DIRECTIVES = { 
    :qb => [:qbxml, { version: '6.0' }],
    :qbpos => [:qbposxml, { version: '3.0' }]
  }.freeze

  FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}
  BOOL_CAST  = Proc.new {|d| d ? (d == 'True' ? true : false) : false }
  DATE_CAST  = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") }
  TIME_CAST  = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }
  INT_CAST   = Proc.new {|d| d ? Integer(d.to_i) : 0 }
  STR_CAST   = Proc.new {|d| d ? String(d) : ''}

  TYPE_MAP= {
    "AMTTYPE"          => FLOAT_CAST,
    "BOOLTYPE"         => BOOL_CAST,
    "DATETIMETYPE"     => TIME_CAST,
    "DATETYPE"         => DATE_CAST,
    "ENUMTYPE"         => STR_CAST,
    "FLOATTYPE"        => FLOAT_CAST,
    "GUIDTYPE"         => STR_CAST,
    "IDTYPE"           => STR_CAST,
    "INTTYPE"          => INT_CAST,
    "PERCENTTYPE"      => FLOAT_CAST,
    "PRICETYPE"        => FLOAT_CAST,
    "QUANTYPE"         => INT_CAST,
    "STRTYPE"          => STR_CAST,
    "TIMEINTERVALTYPE" => STR_CAST
  }

  ACRONYMS = ['AP', 'AR', 'COGS', 'COM', 'UOM', 'QBXML', 'UI', 'AVS', 'ID',
              'PIN', 'SSN', 'COM', 'CLSID', 'FOB', 'EIN', 'UOM', 'PO', 'PIN', 'QB']

  ActiveSupport::Inflector.inflections do |inflect|
    ACRONYMS.each { |a| inflect.acronym a }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qbxml-dtd6-1.0.3 lib/qbxml/types.rb
qbxml-dtd6-1.0.2 lib/qbxml/types.rb