Class: Tutorial::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/models/tutorial/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_loaderObject (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

#nameObject (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_languagesObject



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_languageObject



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_productObject



43
44
45
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 43

def default_product
  @default_product ||= products.first
end

#descriptionObject



19
20
21
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 19

def description
  @description ||= yaml['description']
end


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

#productsObject



11
12
13
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 11

def products
  @products ||= yaml['products'] || []
end

#titleObject



15
16
17
# File 'lib/nexmo_developer/app/models/tutorial/metadata.rb', line 15

def title
  @title ||= yaml['title']
end