Class: Yoda::Store::Objects::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/objects/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name:, name: nil, yard_types: [], text: nil, lexical_scope: []) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • tag_name (String)
  • name (String, nil) (defaults to: nil)
  • yard_types (Array<String>) (defaults to: [])
  • text (String, nil) (defaults to: nil)
  • lexical_scope (Array<String>) (defaults to: [])


30
31
32
33
34
35
36
# File 'lib/yoda/store/objects/tag.rb', line 30

def initialize(tag_name:, name: nil, yard_types: [], text: nil, lexical_scope: [])
  @tag_name = tag_name
  @name = name
  @yard_types = yard_types
  @text = text
  @lexical_scope = lexical_scope
end

Instance Attribute Details

#lexical_scopeArray<String> (readonly)

Returns:

  • (Array<String>)


23
24
25
# File 'lib/yoda/store/objects/tag.rb', line 23

def lexical_scope
  @lexical_scope
end

#nameString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/yoda/store/objects/tag.rb', line 20

def name
  @name
end

#tag_nameString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/yoda/store/objects/tag.rb', line 17

def tag_name
  @tag_name
end

#textString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/yoda/store/objects/tag.rb', line 20

def text
  @text
end

#yard_typesArray<String> (readonly)

Returns:

  • (Array<String>)


23
24
25
# File 'lib/yoda/store/objects/tag.rb', line 23

def yard_types
  @yard_types
end

Class Method Details

.json_creatable?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/yoda/store/objects/tag.rb', line 6

def json_creatable?
  true
end

.json_create(params) ⇒ Object

Parameters:

  • params (Hash)


11
12
13
# File 'lib/yoda/store/objects/tag.rb', line 11

def json_create(params)
  new(params.map { |k, v| [k.to_sym, v] }.select { |(k, v)| %i(tag_name name yard_types text lexical_scope).include?(k) }.to_h)
end

Instance Method Details

#==(another) ⇒ Object



51
52
53
# File 'lib/yoda/store/objects/tag.rb', line 51

def ==(another)
  eql?(another)
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/yoda/store/objects/tag.rb', line 47

def eql?(another)
  self.class == another.class && to_h == another.to_h
end

#hashObject



43
44
45
# File 'lib/yoda/store/objects/tag.rb', line 43

def hash
  ([self.class.name] + to_h.to_a).hash
end

#to_hHash

Returns:

  • (Hash)


39
40
41
# File 'lib/yoda/store/objects/tag.rb', line 39

def to_h
  { name: name, tag_name: tag_name, yard_types: yard_types, text: text, lexical_scope: lexical_scope }
end

#to_json(_state = nil) ⇒ String

Returns:

  • (String)


56
57
58
# File 'lib/yoda/store/objects/tag.rb', line 56

def to_json(_state = nil)
  to_h.merge(json_class: self.class.name).to_json
end