Class: SakamichiScraper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sakamichi_scraper/base.rb

Direct Known Subclasses

Hinatazaka, Sakurazaka

Instance Method Summary collapse

Instance Method Details

#format_content(content) ⇒ Object



14
15
16
# File 'lib/sakamichi_scraper/base.rb', line 14

def format_content(content)
  content.gsub(/[\r\n\s]/, "")
end

#format_timestamp(datetime) ⇒ Object



18
19
20
# File 'lib/sakamichi_scraper/base.rb', line 18

def format_timestamp(datetime)
  DateTime.parse(datetime).strftime('%Y-%-m-%-d %-H:%-M')
end

#get_content(url) ⇒ Object



8
9
10
11
12
# File 'lib/sakamichi_scraper/base.rb', line 8

def get_content(url)
  URI.open(url, "User-Agent" => "Chrome/86.0.4240.80") do |f|
    f.read
  end
end

#init_url(group_name, yml_key) ⇒ Object



3
4
5
6
# File 'lib/sakamichi_scraper/base.rb', line 3

def init_url(group_name, yml_key)
  url = YAML.load_file("config/url.yml")["#{group_name}"]["#{yml_key}"]
  get_content(url)
end