Class: WhatIMean::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/whatimean/word.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Word

Instatiate a new Word with following attributes:

Parameters:

  • attributes (Hash)

    Data that will be set in Word.

Options Hash (attributes):

  • :name (String)

    Word name

  • :hits (Fixnum)

    Estimated hit count (occurrences)

  • :rate (Float)

    Rate comparison based on total value



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

def initialize(attributes)
  attributes.each do |key, value|
    send("#{key}=", value)
  end

  self
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



4
5
6
# File 'lib/whatimean/word.rb', line 4

def hits
  @hits
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/whatimean/word.rb', line 4

def name
  @name
end

#rateObject

Returns the value of attribute rate.



4
5
6
# File 'lib/whatimean/word.rb', line 4

def rate
  @rate
end

Instance Method Details

#calculate_rate(total) ⇒ Word

Calculate

Parameters:

  • total (Float)

    The total ammount to be compared

Returns:

  • (Word)

    self object



23
24
25
26
# File 'lib/whatimean/word.rb', line 23

def calculate_rate(total)
  self.rate = hits / total.to_f
  self
end