Class: Edmunds::Vehicle::Specification::Style::StylesDetails

Inherits:
Object
  • Object
show all
Defined in:
lib/edmunds/vehicle/specification/style.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ StylesDetails



47
48
49
50
# File 'lib/edmunds/vehicle/specification/style.rb', line 47

def initialize(attributes)
  @count = attributes['stylesCount']
  @styles = attributes['styles'].map { |json| Style.new(json) } if attributes.key?('styles')
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



45
46
47
# File 'lib/edmunds/vehicle/specification/style.rb', line 45

def count
  @count
end

#stylesObject (readonly)

Returns the value of attribute styles.



45
46
47
# File 'lib/edmunds/vehicle/specification/style.rb', line 45

def styles
  @styles
end

Class Method Details

.find(make_name, model_name, model_year, api_params = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/edmunds/vehicle/specification/style.rb', line 52

def self.find(make_name, model_name, model_year, api_params = {})
  response = Edmunds::Api.get("#{BASE_API_URL}/#{make_name}/#{model_name}/#{model_year}/styles") do |request|
    request.raw_parameters = api_params

    request.allowed_parameters = {
      submodel: Edmunds::Vehicle::SUBMODEL_REGEX,
      category: Edmunds::Vehicle::VEHICLE_CATEGORIES,
      state: %w[new used future],
      year: ((1990.to_s)..(Date.current.year.to_s)),
      view: %w[basic full],
      fmt:  %w[json]
    }

    request.default_parameters = { view: 'basic', fmt: 'json' }

    request.required_parameters = %w[fmt]
  end

  attributes = JSON.parse(response.body)
  new(attributes)
end