Class: EOAT::Result::EveType::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/eoat/result/eve_type.rb

Overview

Parser class of of EVE API xml. Has the structure of the xml root. Starting from ['eveapi']

Examples:

eve = EOAT::Result::EveType::Result.new(xml_to_hash)
eve.from_cache #=> false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Result

Returns a new instance of Result.

Parameters:

  • hash (Hash)

    the xml body parsed to hash



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/eoat/result/eve_type.rb', line 26

def initialize(hash)
  hash = hash.key?('eveapi') ? hash['eveapi'] : EOAT::Exception::ParseError.new('Wrong parse data')
  @from_cache = false
  @cached_until = Time.parse(hash['cachedUntil'] + 'UTC')
  @request_time = Time.parse(hash['currentTime'] + 'UTC')
  @result = hash['result'].keys - Array.new(1, 'rowset')
  hash['result'].keys.each do |key|
    value = hash['result'][key]
    case value
      when Hash
        if value.key? 'row'
          var_name = value['name']
          var_value = RowSet.new(value)
          @result << var_name
        else
          var_name = key
          var_value = Row.new(value)
        end
        self.instance_variable_set("@#{var_name}", var_value)
        self.class.send(
            :define_method,
            var_name,
            proc{self.instance_variable_get("@#{var_name}")}
        )
      when Array
        value.each do |v|
          self.instance_variable_set("@#{v['name']}", RowSet.new(v))
          self.class.send(
              :define_method,
              v['name'],
              proc{self.instance_variable_get("@#{v['name']}")}
          )
          @result << v['name']
        end
      when String
        self.instance_variable_set("@#{key}", value)
        self.class.send(
            :define_method,
            key,
            proc{self.instance_variable_get("@#{key}")}
        )
      else
        raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{value}"
    end
  end
end

Instance Attribute Details

#cached_untilObject

Returns the value of attribute cached_until.



23
24
25
# File 'lib/eoat/result/eve_type.rb', line 23

def cached_until
  @cached_until
end

#from_cacheObject

Return true if data from cache



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/eoat/result/eve_type.rb', line 21

class Result
  attr_accessor :from_cache
  attr_reader :cached_until, :request_time, :result

  # @param [Hash] hash the xml body parsed to hash
  def initialize(hash)
    hash = hash.key?('eveapi') ? hash['eveapi'] : EOAT::Exception::ParseError.new('Wrong parse data')
    @from_cache = false
    @cached_until = Time.parse(hash['cachedUntil'] + 'UTC')
    @request_time = Time.parse(hash['currentTime'] + 'UTC')
    @result = hash['result'].keys - Array.new(1, 'rowset')
    hash['result'].keys.each do |key|
      value = hash['result'][key]
      case value
        when Hash
          if value.key? 'row'
            var_name = value['name']
            var_value = RowSet.new(value)
            @result << var_name
          else
            var_name = key
            var_value = Row.new(value)
          end
          self.instance_variable_set("@#{var_name}", var_value)
          self.class.send(
              :define_method,
              var_name,
              proc{self.instance_variable_get("@#{var_name}")}
          )
        when Array
          value.each do |v|
            self.instance_variable_set("@#{v['name']}", RowSet.new(v))
            self.class.send(
                :define_method,
                v['name'],
                proc{self.instance_variable_get("@#{v['name']}")}
            )
            @result << v['name']
          end
        when String
          self.instance_variable_set("@#{key}", value)
          self.class.send(
              :define_method,
              key,
              proc{self.instance_variable_get("@#{key}")}
          )
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{value}"
      end
    end
  end
end

#request_timeObject

Returns the value of attribute request_time.



23
24
25
# File 'lib/eoat/result/eve_type.rb', line 23

def request_time
  @request_time
end

#resultObject (readonly)

List of children



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/eoat/result/eve_type.rb', line 21

class Result
  attr_accessor :from_cache
  attr_reader :cached_until, :request_time, :result

  # @param [Hash] hash the xml body parsed to hash
  def initialize(hash)
    hash = hash.key?('eveapi') ? hash['eveapi'] : EOAT::Exception::ParseError.new('Wrong parse data')
    @from_cache = false
    @cached_until = Time.parse(hash['cachedUntil'] + 'UTC')
    @request_time = Time.parse(hash['currentTime'] + 'UTC')
    @result = hash['result'].keys - Array.new(1, 'rowset')
    hash['result'].keys.each do |key|
      value = hash['result'][key]
      case value
        when Hash
          if value.key? 'row'
            var_name = value['name']
            var_value = RowSet.new(value)
            @result << var_name
          else
            var_name = key
            var_value = Row.new(value)
          end
          self.instance_variable_set("@#{var_name}", var_value)
          self.class.send(
              :define_method,
              var_name,
              proc{self.instance_variable_get("@#{var_name}")}
          )
        when Array
          value.each do |v|
            self.instance_variable_set("@#{v['name']}", RowSet.new(v))
            self.class.send(
                :define_method,
                v['name'],
                proc{self.instance_variable_get("@#{v['name']}")}
            )
            @result << v['name']
          end
        when String
          self.instance_variable_set("@#{key}", value)
          self.class.send(
              :define_method,
              key,
              proc{self.instance_variable_get("@#{key}")}
          )
        else
          raise EOAT::Exception::ParseError.new "Unable to parse the the value of #{value}"
      end
    end
  end
end