class RealPage::Utils::ArrayFetcher
Fetch an array from a hash that was generated by parsing XML using MultiXml. If you provide a model to instantiate, an instance will be initialized with each data element.
Attributes
hash[R]
key[R]
model[R]
Public Class Methods
new(hash:, key:, model: nil)
click to toggle source
# File lib/real_page/utils/array_fetcher.rb, line 9 def initialize(hash:, key:, model: nil) @hash = hash @key = key @model = model end
Public Instance Methods
fetch()
click to toggle source
@return [Array] take the MultiXml hash and return a proper array
# File lib/real_page/utils/array_fetcher.rb, line 16 def fetch return [] if empty? value = hash[key] value = [value] unless value.is_a?(Array) return value unless model value.map { |v| model.new(v) } end
Private Instance Methods
empty?()
click to toggle source
# File lib/real_page/utils/array_fetcher.rb, line 28 def empty? return true if hash.nil? return true if hash.is_a?(String) && hash.strip! == '' hash.empty? end