Sha256: fa2081c20b6e70f5162d6def6fdf0ba61260a7554b175b6ba1522a56d9b7daeb

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module MrYahooFinance
  module Builder
    module Format
      module Indicator

        class << self
          def periods(element, count)
            [].tap do |data|
              (2..(count+1)).each do |number|
                data << build_text(element, number).to_i
              end
            end
          end

        private
          def build_text(element, number)
            if negative?(element, number)
              '-'.concat(extract(element, number).to_i.to_s)
            else
              extract(element, number)
            end
          end

          def negative?(element, number)
            element.css("td[#{number}]").text.include?('(')
          end

          def extract(element, number)
            element.css("td[#{number}]").text.delete(',').delete('(').delete(')')
          end
        end
      end

      module Period

        class << self
          def periods(element, count)
            [].tap do |ary|
              (0..(count-1)).map{|n| ary << element.css('th')[n].text}
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mr_yahoo_finance-0.1.0 lib/mr_yahoo_finance/builder/format.rb