Class: TF2R::Raffle

Inherits:
Object
  • Object
show all
Includes:
TextHelpers
Defined in:
lib/tf2r/raffle.rb

Overview

This class provides a simple wrapper around grabbing information for a raffle from the Scraper and API. TODO: document

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextHelpers

#extract_color, #extract_link_snippet, #extract_steam_id, #raffle_link, #raffle_link_full, #user_link

Constructor Details

#initialize(link_snippet) ⇒ Raffle

Returns a new instance of Raffle.



10
11
12
13
14
15
16
# File 'lib/tf2r/raffle.rb', line 10

def initialize(link_snippet)
  @link_snippet = link_snippet

  @scraper = Scraper.new
  populate_raffle_info
  get_full_participants if max_entries > API::MAX_ENTRY_RESPONSE_COUNT
end

Instance Attribute Details

Returns the value of attribute link_snippet.



8
9
10
# File 'lib/tf2r/raffle.rb', line 8

def link_snippet
  @link_snippet
end

Instance Method Details

#creatorObject

Gives information about the raffle’s creator.

Taken straight from Scraper.



59
60
61
# File 'lib/tf2r/raffle.rb', line 59

def creator
  @scraper_info[1]
end

#infoHash

Gives information about the raffle.

Examples:

r = Raffle.new('kstzcbd')
r.info #=>
{:link_snippet=>"kstzcbd",
 :title=>"Just one refined [1 hour]",
 :description=>"Plain and simple.",
 :start_time=>2012-10-29 09:51:45 -0400,
 :end_time=>2012-10-29 09:53:01 -0400,
 :win_chance=>0.1,
 :current_entries=>10,
 :max_entries=>10,
 :is_done=>true}

Parameters:

  • page (Mechanize::Page)

    the raffle page.

Returns:

  • (Hash)

    a representation of the raffle.

    • :link_snippet (String) — the “raffle id” in the URL.

    • :title (String) — the raffle’s title.

    • :description (String) — the raffle’s “message”.

    • :start_time (Time) — the creation time of the raffle.

    • :end_time (Time) — the projects/observed end time for the raffle.

    • :win_chance (Float) — a participant’s chance to win the raffle. Rounded to 5 digits.

    • :current_entries (Fixnum) — the current number of participants.

    • :max_entries (Fixnum) — the maximum number of particpants allowed.

    • :is_done (Boolean) — whether new users can enter the raffle.



46
47
48
49
50
51
52
# File 'lib/tf2r/raffle.rb', line 46

def info
  @info ||= {link_snippet: @link_snippet, title: title,
             description: description, start_time: start_time,
             end_time: end_time, win_chance: win_chance,
             current_entries: current_entries, max_entries: max_entries,
             is_done: is_done}
end

#participantsObject

TODO: test raffles with max_entries greater than 2500



64
65
66
67
68
69
70
# File 'lib/tf2r/raffle.rb', line 64

def participants
  if max_entries > API::MAX_ENTRY_RESPONSE_COUNT
    @full_participants
  else
    @normalized_participants ||= normalize_entries(@api_info['newentry'])
  end
end