Sha256: e419c46c2a51c7a5fb03c3e4596308703c999f1126f3c383eec66c2ce7ec44f2

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

require 'real_page/attribute_parser/boolean'
require 'real_page/attribute_parser/date'
require 'real_page/attribute_parser/date_time'
require 'real_page/attribute_parser/decimal'
require 'real_page/attribute_parser/integer'
require 'real_page/attribute_parser/object'
require 'real_page/attribute_parser/string'

module RealPage
  # Parse the string value from the XML response into the configured data type
  class AttributeParser
    # @param value [String] the response value from RealPage
    # @param type [Symbol] the attribute's configured data type
    def initialize(value:, type:)
      @value = value
      @type = type
    end

    # @return [Object] the parsed attribute value
    def parse
      return unless value
      case type
      when :boolean
        AttributeParser::Boolean.new(value).parse
      when :date
        AttributeParser::Date.new(value).parse
      when :date_time
        AttributeParser::DateTime.new(value).parse
      when :decimal
        AttributeParser::Decimal.new(value).parse
      when :integer
        AttributeParser::Integer.new(value).parse
      when :object
        AttributeParser::Object.new(value).parse
      when :string
        AttributeParser::String.new(value).parse
      else
        raise ArgumentError, "Invalid attribute type: #{type}"
      end
    end

    private

    attr_reader :value, :type
  end

  private_constant :AttributeParser
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
real_page-2.3.6 lib/real_page/attribute_parser.rb
real_page-2.3.5 lib/real_page/attribute_parser.rb
real_page-2.3.4 lib/real_page/attribute_parser.rb
real_page-2.3.3 lib/real_page/attribute_parser.rb
real_page-2.3.2 lib/real_page/attribute_parser.rb
real_page-2.3.1 lib/real_page/attribute_parser.rb
real_page-2.3.0 lib/real_page/attribute_parser.rb