Class: WordsApi::FrequencyDetails

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/words_api/models/frequency_details.rb

Overview

This model contains frequency details of a specific word.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(zipf = nil, per_million = nil, diversity = nil) ⇒ FrequencyDetails

Returns a new instance of FrequencyDetails.



43
44
45
46
47
# File 'lib/words_api/models/frequency_details.rb', line 43

def initialize(zipf = nil, per_million = nil, diversity = nil)
  @zipf = zipf
  @per_million = per_million
  @diversity = diversity
end

Instance Attribute Details

#diversityFloat

Explains the diversity score.

Returns:

  • (Float)


22
23
24
# File 'lib/words_api/models/frequency_details.rb', line 22

def diversity
  @diversity
end

#per_millionFloat

Explains the perMillion score.

Returns:

  • (Float)


18
19
20
# File 'lib/words_api/models/frequency_details.rb', line 18

def per_million
  @per_million
end

#zipfFloat

Explains the zipf score.

Returns:

  • (Float)


14
15
16
# File 'lib/words_api/models/frequency_details.rb', line 14

def zipf
  @zipf
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/words_api/models/frequency_details.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  zipf = hash.key?('zipf') ? hash['zipf'] : nil
  per_million = hash.key?('perMillion') ? hash['perMillion'] : nil
  diversity = hash.key?('diversity') ? hash['diversity'] : nil

  # Create object from extracted values.
  FrequencyDetails.new(zipf,
                       per_million,
                       diversity)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/words_api/models/frequency_details.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['zipf'] = 'zipf'
  @_hash['per_million'] = 'perMillion'
  @_hash['diversity'] = 'diversity'
  @_hash
end

.nullablesObject

An array for nullable fields



39
40
41
# File 'lib/words_api/models/frequency_details.rb', line 39

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
# File 'lib/words_api/models/frequency_details.rb', line 34

def self.optionals
  []
end