Sha256: eec9048d86e0668eb09e15d452fa96d4f2dbc439455ed471c07d3f07388e0039

Contents?: true

Size: 1.15 KB

Versions: 94

Compression:

Stored size: 1.15 KB

Contents

class Tutorial::Metadata
  attr_reader :name, :file_loader

  delegate :path, :yaml, to: :file_loader

  def initialize(name:)
    @name        = name
    @file_loader = load_file!
  end

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

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

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

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

  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

  def code_language
    @code_language ||= begin
      available_code_languages
        .min_by { |k| Nexmo::Markdown::CodeLanguage.languages.map(&:key).index(k) }
    end
  end

  def default_product
    @default_product ||= products.first
  end

  def load_file!
    Tutorial::FileLoader.new(
      root: Tutorial.tutorials_path,
      code_language: nil,
      doc_name: @name
    )
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.15 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.14 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.13 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.12 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.11 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.10 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.9 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.8 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.7 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.6 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.5 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.4 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.3 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.2 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.1 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.5.0 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.4.9 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.4.8 lib/nexmo_developer/app/models/tutorial/metadata.rb
station-0.4.7 lib/nexmo_developer/app/models/tutorial/metadata.rb