Class: Tutorial::Metadata
- Inherits:
-
Object
- Object
- Tutorial::Metadata
- Defined in:
- lib/nexmo_developer/app/models/tutorial/metadata.rb
Instance Attribute Summary collapse
-
#file_loader ⇒ Object
readonly
Returns the value of attribute file_loader.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #available_code_languages ⇒ Object
- #code_language ⇒ Object
- #default_product ⇒ Object
- #description ⇒ Object
- #external_link ⇒ Object
-
#initialize(name:) ⇒ Metadata
constructor
A new instance of Metadata.
- #load_file! ⇒ Object
- #products ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(name:) ⇒ Metadata
Returns a new instance of Metadata.
6 7 8 9 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 6 def initialize(name:) @name = name @file_loader = load_file! end |
Instance Attribute Details
#file_loader ⇒ Object (readonly)
Returns the value of attribute file_loader.
2 3 4 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 2 def file_loader @file_loader end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 2 def name @name end |
Instance Method Details
#available_code_languages ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 27 def available_code_languages @available_code_languages ||= begin Nexmo::Markdown::DocFinder .code_languages_for_tutorial(path: path.sub('.yml', '/')) .map { |file_path| File.basename(Pathname.new(file_path).basename, '.yml') } .sort_by { |l| Nexmo::Markdown::CodeLanguage.find(l).weight } end end |
#code_language ⇒ Object
36 37 38 39 40 41 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 36 def code_language @code_language ||= begin available_code_languages .min_by { |k| Nexmo::Markdown::CodeLanguage.languages.map(&:key).index(k) } end end |
#default_product ⇒ Object
43 44 45 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 43 def default_product @default_product ||= products.first end |
#description ⇒ Object
19 20 21 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 19 def description @description ||= yaml['description'] end |
#external_link ⇒ Object
23 24 25 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 23 def external_link @external_link ||= yaml['external_link'] end |
#load_file! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 47 def load_file! Tutorial::FileLoader.new( root: Tutorial.tutorials_path, code_language: nil, doc_name: @name ) end |
#products ⇒ Object
11 12 13 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 11 def products @products ||= yaml['products'] || [] end |
#title ⇒ Object
15 16 17 |
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 15 def title @title ||= yaml['title'] end |