Class: ScrapCbf

Inherits:
Object
  • Object
show all
Includes:
Formattable, Printable
Defined in:
lib/scrap_cbf.rb,
lib/scrap_cbf/errors.rb,
lib/scrap_cbf/version.rb,
lib/scrap_cbf/document.rb,
lib/scrap_cbf/printable.rb,
lib/scrap_cbf/formattable.rb,
lib/scrap_cbf/models/team.rb,
lib/scrap_cbf/models/match.rb,
lib/scrap_cbf/models/round.rb,
lib/scrap_cbf/models/ranking.rb,
lib/scrap_cbf/models/table/row.rb,
lib/scrap_cbf/models/table/cell.rb,
lib/scrap_cbf/models/championship.rb,
lib/scrap_cbf/helpers/lib/findable.rb,
lib/scrap_cbf/helpers/teams_helper.rb,
lib/scrap_cbf/builders/teams_builder.rb,
lib/scrap_cbf/helpers/matches_helper.rb,
lib/scrap_cbf/builders/rounds_builder.rb,
lib/scrap_cbf/helpers/rankings_helper.rb,
lib/scrap_cbf/builders/matches_builder.rb,
lib/scrap_cbf/helpers/lib/depth_search.rb,
lib/scrap_cbf/builders/rankings_builder.rb,
lib/scrap_cbf/models/table/header_column.rb,
lib/scrap_cbf/helpers/lib/element_nokogiri.rb,
lib/scrap_cbf/builders/matches_per_round_builder.rb

Overview

ScrapCbf is a gem created for scraping data from the CBF official page. Some of the data found on the CBF page are: teams, matches, rounds and ranking table from all championships founded on the official page.

Defined Under Namespace

Modules: DepthSearch, ElementNokogiri, Findable, Formattable, MatchesHelper, Printable, RankingsHelper, TeamsHelper Classes: BaseError, Cell, Championship, Document, HeaderColumn, InvalidNumberOfEntitiesError, Match, MatchesBuilder, MatchesPerRoundBuilder, MethodMissingError, MethodNotImplementedError, MissingArgumentError, OutOfRangeArgumentError, Ranking, RankingsBuilder, Round, RoundsBuilder, Row, RowSizeError, Team, TeamsBuilder

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Printable

#print

Methods included from Formattable

#to_json

Constructor Details

#initialize(opts = {}) ⇒ ScrapCbf

Returns new instance.

Options Hash (opts):

  • :year (Integer)

    The Championship year.

  • :serie (Symbol)

    The Championship serie.

  • :load_from_sample (Symbol)

    Load championship from sample.

  • :sample_path (Symbol)

    to the sample otherwise default



52
53
54
55
56
57
58
59
# File 'lib/scrap_cbf.rb', line 52

def initialize(opts = {})
  year = opts.fetch(:year, Date.today.year.to_i)
  serie = opts.fetch(:serie, :serie_a)

  @document = Document.new(year, serie, opts)
  @parsed_document = @document.parsed_document
  @championship = Championship.new(year, serie)
end

Instance Attribute Details

#championshipScrapCbf::Championship (readonly)



42
# File 'lib/scrap_cbf.rb', line 42

attr_reader :document

#documentObject (readonly)

Returns the value of attribute document.



42
43
44
# File 'lib/scrap_cbf.rb', line 42

def document
  @document
end

Instance Method Details

#matchesMatchesBuilder



74
75
76
# File 'lib/scrap_cbf.rb', line 74

def matches
  @matches ||= rounds.matches_builder
end

#rankingsRankingsBuilder



79
80
81
# File 'lib/scrap_cbf.rb', line 79

def rankings
  @rankings ||= RankingsBuilder.new(@parsed_document, @championship)
end

#roundsRoundsBuilder



84
85
86
# File 'lib/scrap_cbf.rb', line 84

def rounds
  @rounds ||= RoundsBuilder.new(@parsed_document, @championship)
end

#teamsTeamsBuilder



89
90
91
# File 'lib/scrap_cbf.rb', line 89

def teams
  @teams ||= TeamsBuilder.new(@parsed_document)
end

#to_hObject

returns all entities scraped in hash format.



62
63
64
65
66
67
68
69
70
71
# File 'lib/scrap_cbf.rb', line 62

def to_h
  {
    championship: championship.to_h,
    matches: matches.to_h,
    rankings: rankings.to_h,
    rounds: rounds.to_h,
    teams: teams.to_h

  }.with_indifferent_access
end