Class: PAProxyData
- Inherits:
-
Object
- Object
- PAProxyData
- Defined in:
- lib/pa_proxies/pa_proxy_data.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #collect ⇒ Object
- #data_length ⇒ Object
-
#initialize(p_data = {}, p_logger = nil) ⇒ PAProxyData
constructor
A new instance of PAProxyData.
- #length ⇒ Object
- #load(file_name) ⇒ Object
- #new_instance(p_data) ⇒ Object
Constructor Details
#initialize(p_data = {}, p_logger = nil) ⇒ PAProxyData
Returns a new instance of PAProxyData.
8 9 10 11 12 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 8 def initialize(p_data = {}, p_logger = nil) self.data = p_data self.logger = p_logger self end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 5 def data @data end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 6 def logger @logger end |
Instance Method Details
#[](index) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 43 def [](index) if @data.is_a? Array if index == :r return new_instance(@data[rand(@data.length)]) elsif index < @data.length return new_instance(@data[index]) else raise 'out of bonds' end else raise 'Non array' end end |
#collect ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 27 def collect out_array = RArray.new for i in 0...@data.length out_array << yield(new_instance(@data[i])) end out_array end |
#data_length ⇒ Object
14 15 16 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 14 def data_length @data.length end |
#length ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 35 def length if @data.is_a? Array return @data.length else raise 'Not an array' end end |
#load(file_name) ⇒ Object
18 19 20 21 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 18 def load(file_name) self.data = HashAddOn.symbolize_keys_recursive_for_hash(YAML::load(File.read(file_name)), true) self end |
#new_instance(p_data) ⇒ Object
23 24 25 |
# File 'lib/pa_proxies/pa_proxy_data.rb', line 23 def new_instance(p_data) return self.class.new(p_data, self.logger) end |