Class: MostHauntedCli::States

Inherits:
Object
  • Object
show all
Defined in:
lib/most_haunted/states.rb

Constant Summary collapse

@@haunted =
[]
@@states =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ States

Returns a new instance of States.



7
8
9
10
# File 'lib/most_haunted/states.rb', line 7

def initialize(name)
   @name = name
   @@haunted << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/most_haunted/states.rb', line 2

def name
  @name
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/most_haunted/states.rb', line 2

def url
  @url
end

Class Method Details

.add_urlsObject



54
55
56
57
58
59
# File 'lib/most_haunted/states.rb', line 54

def self.add_urls
    u = MostHauntedCli::Scraper.scrape_state_url
    self.haunted.each.with_index do |h, i|
        h.url = u[i]
    end
end

.create_columns(slice) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/most_haunted/states.rb', line 32

def self.create_columns(slice)
    l = slice[0].length
    if l >= 24
        puts "#{slice[0]}"+"      "+"#{slice[1]}"
    else
        puts "#{slice[0]}"+" " * (30 - l)+"#{slice[1]}"
    end 
end

.create_state(array) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/most_haunted/states.rb', line 12

def self.create_state(array)
    array.each do |s|
        name = s
        self.new(name)
    end
    add_urls
end

.hauntedObject



20
21
22
# File 'lib/most_haunted/states.rb', line 20

def self.haunted
    @@haunted
end

.open_state_info(input) ⇒ Object

Individual State Information



49
50
51
52
# File 'lib/most_haunted/states.rb', line 49

def self.open_state_info(input)
    info = MostHauntedCli::Scraper.scrape_state_locations(input)
    info.each{|i| puts i.gsub(' –', '.')}
end

.state_columnsObject



41
42
43
44
45
# File 'lib/most_haunted/states.rb', line 41

def self.state_columns
    states_list.each.each_slice(2) do |slice|
        create_columns(slice)
    end
end

.statesObject



24
25
26
# File 'lib/most_haunted/states.rb', line 24

def self.states
    @@states
end

.states_listObject



28
29
30
# File 'lib/most_haunted/states.rb', line 28

def self.states_list
    self.haunted.collect.with_index(1){|s, i| "#{i}. #{s.name}"}
end