class BarchartData::ScrapeNewHighsNewLows

Public Instance Methods

add_datestamp(hash) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 62
def add_datestamp hash
  hash[:saved_on] = Time.now.strftime("%Y-%m-%d")
end
convert_field_names_to_symbols(array, arg) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 44
def convert_field_names_to_symbols array, arg
  keyed_array = []
  hash = { "1-Month" => :"one_month_#{arg}", "3-Month" => :"three_month_#{arg}",
           "6-Month" => :"six_month_#{arg}", "52-Week" => :"twelve_month_#{arg}",
           "YTD" => :"ytd_#{arg}", "All-Time" => :"all_time_#{arg}" }

  array.each { |elem| hash.include?(elem) ? keyed_array << hash[elem] : keyed_array << elem }
  keyed_array
end
convert_stringy_numbers_to_int(array) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 33
def convert_stringy_numbers_to_int array
  array.map! { |elem| elem !~ /\D/ ? elem.to_i : elem }
  array
end
extract_table_data_with_class_even(page) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 4
def extract_table_data_with_class_even page
  array = page.search('.even').map { |e| e.text() }
  array = prune_array_data array
  array.map! { |elem| elem.split }
end
extract_table_data_with_class_odd(page) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 10
def extract_table_data_with_class_odd page
  array = page.search('.odd').map { |e| e.text() }
  array = prune_array_data array
  array.map! { |elem| elem.split }
end
extract_values(array) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 22
def extract_values array
  temp = []
  array.each do |elem|
    elem.each_with_index do |e, i|
      temp << e if i == 0 || i == 2
    end
  end
  temp
  # remove_extraneous_elements temp
end
hash_data_before_insertion(array) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 58
def hash_data_before_insertion array
  array.each_slice(2).to_h
end
insert_data(high_low) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 66
def insert_data high_low
  HighLow.create(high_low)
end
merge_high_low(highs, lows) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 54
def merge_high_low highs, lows
  highs + lows
end
prune_array_data(arr) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 16
def prune_array_data arr
  ten = arr[10]
  arr.slice!(5..15)
  arr << ten
end
validate_data_integrity(array) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 38
def validate_data_integrity array
  return false unless array.partition { |v| v.is_a? String }[0].count == 6
  return false unless array.partition { |v| v.is_a? Integer }[0].count == 6
  array
end

Private Instance Methods

remove_extraneous_elements(array) click to toggle source
# File lib/barchart_scripts/scrape_new_highs_new_lows.rb, line 71
def remove_extraneous_elements array
  array.slice!(10,10)
  array
end