Class: TutorialListItem
- Inherits:
-
Object
- Object
- TutorialListItem
- Defined in:
- lib/nexmo_developer/app/presenters/tutorial_list_item.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#product ⇒ Object
Returns the value of attribute product.
Instance Method Summary collapse
- #as_json ⇒ Object
- #available_languages ⇒ Object
- #description ⇒ Object
- #external_link ⇒ Object
- #filename ⇒ Object
-
#first_step ⇒ Object
rubocop:enable Naming/PredicateName.
-
#initialize(path) ⇒ TutorialListItem
constructor
A new instance of TutorialListItem.
-
#is_file? ⇒ Boolean
rubocop:disable Naming/PredicateName.
- #is_task? ⇒ Boolean
- #languages ⇒ Object
- #product_url ⇒ Object
-
#products ⇒ Object
rubocop:disable Rails/Delegate.
- #root ⇒ Object
- #subtitle ⇒ Object
- #title ⇒ Object
- #tutorial ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(path) ⇒ TutorialListItem
Returns a new instance of TutorialListItem.
5 6 7 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 5 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 3 def path @path end |
#product ⇒ Object
Returns the value of attribute product.
2 3 4 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 2 def product @product end |
Instance Method Details
#as_json ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 82 def as_json { root: root, path: path, filename: filename, external_link: external_link, first_step: first_step, languages: languages, title: title, description: description, products: products, subtitle: subtitle, is_file?: is_file?, is_task?: is_task?, product: product, } end |
#available_languages ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 72 def available_languages languages.map do |language| OpenStruct.new( language: language, label: Nexmo::Markdown::CodeLanguage.find(language).label, url: external_link || "/#{products.join}/tutorials/#{filename}/#{first_step}/#{language}" ) end end |
#description ⇒ Object
40 41 42 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 40 def description tutorial..description end |
#external_link ⇒ Object
32 33 34 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 32 def external_link tutorial..external_link end |
#filename ⇒ Object
28 29 30 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 28 def filename File.basename(@path, '.yml') end |
#first_step ⇒ Object
rubocop:enable Naming/PredicateName
58 59 60 61 62 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 58 def first_step return if tutorial..external_link tutorial.first_step end |
#is_file? ⇒ Boolean
rubocop:disable Naming/PredicateName
49 50 51 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 49 def is_file? true end |
#is_task? ⇒ Boolean
53 54 55 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 53 def is_task? true end |
#languages ⇒ Object
20 21 22 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 20 def languages @languages ||= tutorial.available_code_languages.map(&:downcase) end |
#product_url ⇒ Object
64 65 66 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 64 def product_url "/#{I18n.locale}/#{products.join}/tutorials" end |
#products ⇒ Object
rubocop:disable Rails/Delegate
44 45 46 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 44 def products # rubocop:disable Rails/Delegate tutorial.products end |
#root ⇒ Object
24 25 26 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 24 def root "#{Rails.configuration.docs_base_path}/config/tutorials" end |
#subtitle ⇒ Object
13 14 15 16 17 18 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 13 def subtitle products .map { |product| Product.normalize_title(product) } .sort .to_sentence end |
#title ⇒ Object
36 37 38 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 36 def title tutorial..title end |
#tutorial ⇒ Object
9 10 11 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 9 def tutorial @tutorial ||= Tutorial.load(File.basename(@path, '.yml'), nil) end |
#url ⇒ Object
68 69 70 |
# File 'lib/nexmo_developer/app/presenters/tutorial_list_item.rb', line 68 def url external_link || "/#{I18n.locale}/#{products.join}/tutorials/#{filename}/#{first_step}" end |