Class: Nexmo::Markdown::CodeLanguage

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/nexmo_markdown_renderer/models/code_language.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def dependencies
  @dependencies
end

#iconObject

Returns the value of attribute icon.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def icon
  @icon
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def key
  @key
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def label
  @label
end

#languagesObject



26
27
28
29
30
31
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 26

def languages
  @languages ||= []
  @languages.map do |language|
    self.class.find(language)
  end
end

#lexerObject



21
22
23
24
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 21

def lexer
  return Rouge::Lexers::PHP.new({ start_inline: true }) if @lexer == 'php'
  Rouge::Lexer.find(@lexer) || Rouge::Lexer.find('text')
end

#linkable=(value) ⇒ Object (writeonly)

Sets the attribute linkable

Parameters:

  • value

    the value to set the attribute linkable to.



6
7
8
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 6

def linkable=(value)
  @linkable = value
end

#run_commandObject

Returns the value of attribute run_command.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def run_command
  @run_command
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def type
  @type
end

#unindentObject

Returns the value of attribute unindent.



5
6
7
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 5

def unindent
  @unindent
end

#versionObject



8
9
10
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 8

def version
  @version || nil
end

#weightObject



12
13
14
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 12

def weight
  @weight || 999
end

Class Method Details

.allObject



49
50
51
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 49

def self.all
  languages + frameworks + terminal_programs + data
end

.dataObject



45
46
47
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 45

def self.data
  where_type('data')
end

.exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 53

def self.exists?(key)
  all.detect { |lang| lang.key == key }
end

.find(key) ⇒ Object



57
58
59
60
61
62
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 57

def self.find(key)
  raise 'Key is missing' unless key
  code_language = all.detect { |lang| lang.key == key }
  raise "Language #{key} does not exist." unless code_language
  code_language
end

.frameworksObject



37
38
39
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 37

def self.frameworks
  where_type('platforms')
end

.languagesObject



33
34
35
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 33

def self.languages
  where_type('languages')
end

.linkableObject



64
65
66
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 64

def self.linkable
  all.select(&:linkable?)
end

.route_constraintObject



68
69
70
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 68

def self.route_constraint
  { code_language: Regexp.new(linkable.map(&:key).compact.join('|')) }
end

.terminal_programsObject



41
42
43
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 41

def self.terminal_programs
  where_type('terminal_programs')
end

Instance Method Details

#linkable?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/nexmo_markdown_renderer/models/code_language.rb', line 16

def linkable?
  return true if @linkable.nil?
  @linkable
end