Class: MartialArts::Styles

Inherits:
Object
  • Object
show all
Defined in:
lib/martial_arts/styles.rb

Constant Summary collapse

@@all =
[]
[]
@@missing_info =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style, country, fighting_focus, website, description) ⇒ Styles

Returns a new instance of Styles.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/martial_arts/styles.rb', line 9

def initialize(style, country, fighting_focus, website, description)
  @name = style
  @country = MartialArts::Countries.new(country)
  @fighting_focus = MartialArts::FightingFocus.new(fighting_focus)
  @website = website
  @description = description

  @country.add_style(self)              #every style belongs to a country or fighting_focus
  @fighting_focus.add_style(self)

  self.class.missing_info << self  if country == "N/A" or fighting_focus == "N/A" or description == "N/A"
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/martial_arts/styles.rb', line 3

def country
  @country
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/martial_arts/styles.rb', line 4

def description
  @description
end

#fighting_focusObject

Returns the value of attribute fighting_focus.



3
4
5
# File 'lib/martial_arts/styles.rb', line 3

def fighting_focus
  @fighting_focus
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/martial_arts/styles.rb', line 4

def name
  @name
end

#websiteObject (readonly)

Returns the value of attribute website.



4
5
6
# File 'lib/martial_arts/styles.rb', line 4

def website
  @website
end

Class Method Details

.allObject



30
31
32
# File 'lib/martial_arts/styles.rb', line 30

def self.all
  @@all
end

.duplicates?(style) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/martial_arts/styles.rb', line 51

def self.duplicates?(style)
  self.all.detect {|style_instance| style_instance.name == style}
end

.missing_infoObject



55
56
57
58
# File 'lib/martial_arts/styles.rb', line 55

def self.missing_info
  #use missing_info array to make corrections to retrieve it via the scraper's correct errors method
  @@missing_info
end


34
35
36
37
# File 'lib/martial_arts/styles.rb', line 34

def self.popular
  #top 10 list taken from simpatong website; up-to-date, but list is not dynamic
  @@popular
end

.search_by_country(country) ⇒ Object

need to setup so that cli is getting from country_instance.styles



43
44
45
# File 'lib/martial_arts/styles.rb', line 43

def self.search_by_country(country) #need to setup so that cli is getting from country_instance.styles
  self.styles_list.find_all {|style_instance| style_instance.country_name.strip.include? "#{country}" }
end

.search_by_focus(focus) ⇒ Object

need to setup so that cli is getting from fighting_focus_instance.styles



47
48
49
# File 'lib/martial_arts/styles.rb', line 47

def self.search_by_focus(focus) #need to setup so that cli is getting from fighting_focus_instance.styles
  self.styles_list.find_all {|style_instance| style_instance.fighting_focus_name.strip.include? "#{focus}" }
end

.styles_listObject



39
40
41
# File 'lib/martial_arts/styles.rb', line 39

def self.styles_list
  self.all.sort {|a,b| a.name <=> b.name }
end

Instance Method Details

#country_nameObject



22
23
24
# File 'lib/martial_arts/styles.rb', line 22

def country_name
  self.country.name
end

#fighting_focus_nameObject



26
27
28
# File 'lib/martial_arts/styles.rb', line 26

def fighting_focus_name
  self.fighting_focus.name
end