Class: TinyClassifier::CategoryManager

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny-classifier/category-manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(categories) ⇒ CategoryManager

Returns a new instance of CategoryManager.



20
21
22
23
24
# File 'lib/tiny-classifier/category-manager.rb', line 20

def initialize(categories)
  @categories = categories.strip.split(",")
  normalize_all
  clanup
end

Instance Attribute Details

#chosenObject (readonly)

Returns the value of attribute chosen.



18
19
20
# File 'lib/tiny-classifier/category-manager.rb', line 18

def chosen
  @chosen
end

Instance Method Details

#allObject



26
27
28
# File 'lib/tiny-classifier/category-manager.rb', line 26

def all
  @categories
end

#basenameObject



35
36
37
# File 'lib/tiny-classifier/category-manager.rb', line 35

def basename
  @categories.join("-").downcase
end

#normalize(category) ⇒ Object



39
40
41
42
43
44
# File 'lib/tiny-classifier/category-manager.rb', line 39

def normalize(category)
  category
    .downcase
    .strip
    .capitalize
end

#valid?(category) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/tiny-classifier/category-manager.rb', line 30

def valid?(category)
  category = normalize(category)
  @categories.include?(category)
end