Class: EOAT::Result::EveType::Result
- Inherits:
-
Object
- Object
- EOAT::Result::EveType::Result
- 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']
Instance Attribute Summary collapse
-
#cached_until ⇒ Object
Returns the value of attribute cached_until.
-
#from_cache ⇒ Object
Return
trueif data from cache. -
#request_time ⇒ Object
Returns the value of attribute request_time.
-
#result ⇒ Object
readonly
List of children.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Result
constructor
A new instance of Result.
Constructor Details
#initialize(hash) ⇒ Result
Returns a new instance of Result.
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_until ⇒ Object
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_cache ⇒ Object
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_time ⇒ Object
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 |
#result ⇒ Object (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 |