<commit_before>require "yaml"
require "ostruct"

module Otouto
  class App
    def start
      hostname = Downup::Base.new(
        options: hostnames,
        header_proc: Title.method(:print)
      ).prompt

      route = Downup::Base.new(
        options: route_option_generator(hostname),
        header_proc: Title.method(:print)
      ).prompt

      route_letter, route_hash = routes(hostname).find { |route_letter, route_hash|
        route_hash.fetch("url") == route
      }

      route_obj = OpenStruct.new(route_hash)

      curl_stmt = "curl -A Mozilla " + hostname + route + parse_if_html(route_obj)
      p system(curl_stmt)
    end

    private

    def parse_if_html(route_obj)
      route_obj.content_type == "HTML" ?  " | html2text" : ""
    end

    def route_option_generator(hostname)
      route_info = routes(hostname)
      route_info.keys.map.with_object({}) do |elem, options|
        options[elem] = route_info.fetch(elem).fetch("url")
      end
    end

    def routes(hostname)
      @routes ||= YAML.load_file("config/routes.yml").fetch(hostname)
    end

    def hostnames
      @hostnames ||= YAML.load_file("config/hostnames.yml")
    end

  end
end<commit_msg>separates out headers into method<commit_after>require "yaml"
require "ostruct"

module Otouto
  class App
    def start
      hostname = Downup::Base.new(
        options: hostnames,
        header_proc: Title.method(:print)
      ).prompt

      route = Downup::Base.new(
        options: route_option_generator(hostname),
        header_proc: Title.method(:print)
      ).prompt

      route_letter, route_hash = routes(hostname).find { |route_letter, route_hash|
        route_hash.fetch("url") == route
      }

      route_obj = OpenStruct.new(route_hash)

      curl_stmt = "curl " + headers + hostname + route + parse_if_html(route_obj)
      p system(curl_stmt)
    end

    private

    def parse_if_html(route_obj)
      route_obj.content_type == "HTML" ?  " | html2text" : ""
    end

    def route_option_generator(hostname)
      route_info = routes(hostname)
      route_info.keys.map.with_object({}) do |elem, options|
        options[elem] = route_info.fetch(elem).fetch("url")
      end
    end

    def routes(hostname)
      @routes ||= YAML.load_file("config/routes.yml").fetch(hostname)
    end

    def hostnames
      @hostnames ||= YAML.load_file("config/hostnames.yml")
    end

    def headers
      " -A Mozilla "
    end

  end
end
{'fraction_non_alphanumeric': 0.1120162932790224, 'fraction_numerical': 0.000814663951120163, 'mean_word_length': 2.7268588770864945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021703', 'n_tokens_mistral': 812, 'n_tokens_neox': 788, 'n_words': 155}