Class: ScrapCbf::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/scrap_cbf/document.rb

Overview

This class is responsible for:

  • Handler users input.

  • Fetch html page from CBF official page.

  • Parse html page with Nokogiri.

Constant Summary collapse

URL =
'https://www.cbf.com.br/futebol-brasileiro/competicoes'
CHAMPIONSHIP_YEARS =
(2012..Date.today.year.to_i).to_a.freeze
SERIES =
i[serie_a serie_b].freeze
SERIES_PATH =
{
  serie_a: 'campeonato-brasileiro-serie-a',
  serie_b: 'campeonato-brasileiro-serie-b'
}.freeze
SAMPLE_PATH =
"#{File.dirname(__FILE__)}/samples/" \
'cbf_serie_a_2020.html'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, serie, opts) ⇒ Document

Returns new instance.

Options Hash (opts):

  • load_from_sample (Boolean)

    yes or no to load specific HTML file

  • sample_path (Symbol)

    path to the sample otherwise default



42
43
44
45
46
47
48
49
50
# File 'lib/scrap_cbf/document.rb', line 42

def initialize(year, serie, opts)
  @year = year
  @serie = serie
  @load_from_sample = opts.fetch(:load_from_sample) { false }
  @sample_path = opts[:sample_path]

  @parsed_document =
    parse_document(year, serie, @load_from_sample, @sample_path)
end

Instance Attribute Details

#load_from_sampleObject (readonly)

Returns the value of attribute load_from_sample.



29
30
31
# File 'lib/scrap_cbf/document.rb', line 29

def load_from_sample
  @load_from_sample
end

#parsed_documentObject (readonly)

Returns the value of attribute parsed_document.



29
30
31
# File 'lib/scrap_cbf/document.rb', line 29

def parsed_document
  @parsed_document
end

#sample_pathObject (readonly)

Returns the value of attribute sample_path.



29
30
31
# File 'lib/scrap_cbf/document.rb', line 29

def sample_path
  @sample_path
end

#serieObject (readonly)

Returns the value of attribute serie.



29
30
31
# File 'lib/scrap_cbf/document.rb', line 29

def serie
  @serie
end

#yearObject (readonly)

Returns the value of attribute year.



29
30
31
# File 'lib/scrap_cbf/document.rb', line 29

def year
  @year
end

Class Method Details

.parse_document(year, serie, opts) ⇒ Object



24
25
26
# File 'lib/scrap_cbf/document.rb', line 24

def parse_document(year, serie, opts)
  new(year, serie, opts).parsed_document
end