Class: Cortex::Snippets::Webpage

Inherits:
Object
  • Object
show all
Defined in:
lib/cortex/snippets/webpage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cortex_client, url) ⇒ Webpage

Returns a new instance of Webpage.



6
7
8
9
10
11
# File 'lib/cortex/snippets/webpage.rb', line 6

def initialize(cortex_client, url)
  @url = url
  @response = cortex_client.webpages.get_feed(url)
  @status = @response.status
  @contents = @response.contents
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def contents
  @contents
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/cortex/snippets/webpage.rb', line 4

def url
  @url
end

Instance Method Details

#accordion_group_widget_dataObject



84
85
86
# File 'lib/cortex/snippets/webpage.rb', line 84

def accordion_group_widget_data
  JSON.parse(@contents[:accordion_group_widget_json] || 'null', quirks_mode: true)
end

#accordion_group_widget_data_for(section_name) ⇒ Object



88
89
90
# File 'lib/cortex/snippets/webpage.rb', line 88

def accordion_group_widget_data_for(section_name)
  accordion_group_widget_data&.[](section_name) || []
end

#buy_box_widget_dataObject



96
97
98
# File 'lib/cortex/snippets/webpage.rb', line 96

def buy_box_widget_data
  JSON.parse(@contents[:buy_box_widget_json] || 'null', quirks_mode: true)
end

#carousels_widget_dataObject



68
69
70
# File 'lib/cortex/snippets/webpage.rb', line 68

def carousels_widget_data
  JSON.parse(@contents[:carousels_widget_json] || 'null', quirks_mode: true)
end

#carousels_widget_data_for(section_name) ⇒ Object



72
73
74
# File 'lib/cortex/snippets/webpage.rb', line 72

def carousels_widget_data_for(section_name)
  carousels_widget_data&.[](section_name)
end

#charts_widget_dataObject



92
93
94
# File 'lib/cortex/snippets/webpage.rb', line 92

def charts_widget_data
  JSON.parse(@contents[:charts_widget_json] || 'null', quirks_mode: true)
end

#charts_widget_data_for(section_name) ⇒ Object



100
101
102
# File 'lib/cortex/snippets/webpage.rb', line 100

def charts_widget_data_for(section_name)
  charts_widget_data&.[](section_name) || {}
end

#form_configsObject



108
109
110
# File 'lib/cortex/snippets/webpage.rb', line 108

def form_configs
  @form_configs ||= JSON.parse(@contents[:form_configs_json] || 'null', quirks_mode: true)
end

#galleries_widget_dataObject



76
77
78
# File 'lib/cortex/snippets/webpage.rb', line 76

def galleries_widget_data
  JSON.parse(@contents[:galleries_widget_json] || 'null', quirks_mode: true)
end

#galleries_widget_data_for(section_name) ⇒ Object



80
81
82
# File 'lib/cortex/snippets/webpage.rb', line 80

def galleries_widget_data_for(section_name)
  galleries_widget_data&.[](section_name)
end

#noarchiveObject



52
53
54
# File 'lib/cortex/snippets/webpage.rb', line 52

def noarchive
  @contents[:noarchive]
end

#nofollowObject



40
41
42
# File 'lib/cortex/snippets/webpage.rb', line 40

def nofollow
  @contents[:nofollow]
end

#noimageindexObject



56
57
58
# File 'lib/cortex/snippets/webpage.rb', line 56

def noimageindex
  @contents[:noimageindex]
end

#noindexObject



36
37
38
# File 'lib/cortex/snippets/webpage.rb', line 36

def noindex
  @contents[:noindex]
end

#noodpObject



44
45
46
# File 'lib/cortex/snippets/webpage.rb', line 44

def noodp
  @contents[:noodp]
end

#nosnippetObject



48
49
50
# File 'lib/cortex/snippets/webpage.rb', line 48

def nosnippet
  @contents[:nosnippet]
end

#product_dataObject



104
105
106
# File 'lib/cortex/snippets/webpage.rb', line 104

def product_data
  @product_data ||= JSON.parse(@contents[:product_data_json] || 'null', quirks_mode: true)
end

#seo_descriptionObject



17
18
19
# File 'lib/cortex/snippets/webpage.rb', line 17

def seo_description
  @contents[:seo_description]
end

#seo_keywordsObject



21
22
23
# File 'lib/cortex/snippets/webpage.rb', line 21

def seo_keywords
  @contents[:seo_keyword_list]
end

#seo_robotsObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/cortex/snippets/webpage.rb', line 25

def seo_robots
  robot_information = []
  index_options = [:noindex, :nofollow, :noodp, :nosnippet, :noarchive, :noimageindex]

  index_options.each do |index_option|
    robot_information << index_option if @contents[index_option]
  end

  robot_information
end

#seo_titleObject



13
14
15
# File 'lib/cortex/snippets/webpage.rb', line 13

def seo_title
  @contents[:seo_title]
end

#snippetsObject



112
113
114
# File 'lib/cortex/snippets/webpage.rb', line 112

def snippets
  @contents[:snippets]
end

#tables_widget_dataObject



60
61
62
# File 'lib/cortex/snippets/webpage.rb', line 60

def tables_widget_data
  JSON.parse(@contents[:tables_widget_json] || 'null', quirks_mode: true)
end

#tables_widget_data_for(section_name) ⇒ Object



64
65
66
# File 'lib/cortex/snippets/webpage.rb', line 64

def tables_widget_data_for(section_name)
  tables_widget_data&.[](section_name) || []
end