Class: Awis::Models::CategoryBrowse

Inherits:
Base
  • Object
show all
Defined in:
lib/awis/models/category_browse.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#request_id, #response, #status_code

Instance Method Summary collapse

Methods inherited from Base

#action_name, #loading_response, #pretty_xml, #relationship_collections, #root_node_name, #success?

Constructor Details

#initialize(response) ⇒ CategoryBrowse

Returns a new instance of CategoryBrowse.



8
9
10
11
12
13
14
15
# File 'lib/awis/models/category_browse.rb', line 8

def initialize(response)
  @categories = []
  @language_categories = []
  @related_categories = []
  @letter_bars = []

  super(response)
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



6
7
8
# File 'lib/awis/models/category_browse.rb', line 6

def categories
  @categories
end

#language_categoriesObject

Returns the value of attribute language_categories.



6
7
8
# File 'lib/awis/models/category_browse.rb', line 6

def language_categories
  @language_categories
end

#letter_barsObject

Returns the value of attribute letter_bars.



6
7
8
# File 'lib/awis/models/category_browse.rb', line 6

def letter_bars
  @letter_bars
end

Returns the value of attribute related_categories.



6
7
8
# File 'lib/awis/models/category_browse.rb', line 6

def related_categories
  @related_categories
end

Instance Method Details

#base_node_nameObject

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity rubocop:enable Metrics/MethodLength rubocop:enable Metrics/BlockLength



83
84
85
# File 'lib/awis/models/category_browse.rb', line 83

def base_node_name
  "#{root_node_name}/aws:CategoryBrowse"
end

#category_node_nameObject



87
88
89
# File 'lib/awis/models/category_browse.rb', line 87

def category_node_name
  "#{base_node_name}/aws:Categories/aws:Category"
end

#language_category_node_nameObject



91
92
93
# File 'lib/awis/models/category_browse.rb', line 91

def language_category_node_name
  "#{base_node_name}/aws:LanguageCategories/aws:Category"
end

#letter_bars_node_nameObject



99
100
101
# File 'lib/awis/models/category_browse.rb', line 99

def letter_bars_node_name
  "#{base_node_name}/aws:LetterBars/aws:Category"
end


95
96
97
# File 'lib/awis/models/category_browse.rb', line 95

def related_category_node_name
  "#{base_node_name}/aws:RelatedCategories/aws:Category"
end

#setup_data!(response) ⇒ Object

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/BlockLength



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/awis/models/category_browse.rb', line 22

def setup_data!(response)
  categories = []
  language_categories = []
  related_categories = []
  letter_bars = []

  response.each_node do |node, path|
    text = node.inner_xml
    text = text.to_i if text.to_i.to_s == text
    text = nil if text.class == String && text.empty?

    if node.name == 'aws:RequestId'
      @request_id ||= text
    elsif node.name == 'aws:StatusCode'
      @status_code ||= text
    elsif node.name == 'aws:Path' && path == "#{category_node_name}/aws:Path"
      categories << { path: text }
    elsif node.name == 'aws:Title' && path == "#{category_node_name}/aws:Title"
      categories << { title: text }
    elsif node.name == 'aws:SubCategoryCount' && path == "#{category_node_name}/aws:SubCategoryCount"
      categories << { sub_category_count: text }
    elsif node.name == 'aws:TotalListingCount' && path == "#{category_node_name}/aws:TotalListingCount"
      categories << { total_listing_count: text }
    elsif node.name == 'aws:Path' && path == "#{language_category_node_name}/aws:Path"
      language_categories << { path: text }
    elsif node.name == 'aws:Title' && path == "#{language_category_node_name}/aws:Title"
      language_categories << { title: text }
    elsif node.name == 'aws:SubCategoryCount' && path == "#{language_category_node_name}/aws:SubCategoryCount"
      language_categories << { sub_category_count: text }
    elsif node.name == 'aws:TotalListingCount' && path == "#{language_category_node_name}/aws:TotalListingCount"
      language_categories << { total_listing_count: text }
    elsif node.name == 'aws:Path' && path == "#{related_category_node_name}/aws:Path"
      related_categories << { path: text }
    elsif node.name == 'aws:Title' && path == "#{related_category_node_name}/aws:Title"
      related_categories << { title: text }
    elsif node.name == 'aws:SubCategoryCount' && path == "#{related_category_node_name}/aws:SubCategoryCount"
      related_categories << { sub_category_count: text }
    elsif node.name == 'aws:TotalListingCount' && path == "#{related_category_node_name}/aws:TotalListingCount"
      related_categories << { total_listing_count: text }
    elsif node.name == 'aws:Path' && path == "#{letter_bars_node_name}/aws:Path"
      letter_bars << { path: text }
    elsif node.name == 'aws:Title' && path == "#{letter_bars_node_name}/aws:Title"
      letter_bars << { title: text }
    elsif node.name == 'aws:SubCategoryCount' && path == "#{letter_bars_node_name}/aws:SubCategoryCount"
      letter_bars << { sub_category_count: text }
    elsif node.name == 'aws:TotalListingCount' && path == "#{letter_bars_node_name}/aws:TotalListingCount"
      letter_bars << { total_listing_count: text }
    end
  end

  relationship_collections(@categories, categories, 4, Category)
  relationship_collections(@language_categories, language_categories, 4, LanguageCategory)
  relationship_collections(@related_categories, related_categories, 4, RelatedCategory)
  relationship_collections(@letter_bars, letter_bars, 4, LetterBar)
end