class Yoda::Store::Objects::Base

@abstract

Attributes

document[R]

@return [String]

path[R]

@return [String]

primary_source[R]

@return [(String, Integer, Integer), nil]

sources[R]

@return [Array<(String, Integer, Integer)>]

tag_list[R]

@return [Array<Tag>]

Public Class Methods

attr_names() click to toggle source

@return [Array<Symbol>]

# File lib/yoda/store/objects/base.rb, line 12
def attr_names
  %i(path document tag_list sources primary_source)
end
new(path:, document: '', tag_list: [], sources: [], primary_source: nil, json_class: nil, kind: nil) click to toggle source

@param path [String] @param document [String] @param tag_list [TagList, nil] @param sources [Array<(String, Integer, Integer)>] @param primary_source [(String, Integer, Integer), nil]

# File lib/yoda/store/objects/base.rb, line 37
def initialize(path:, document: '', tag_list: [], sources: [], primary_source: nil, json_class: nil, kind: nil)
  @path = path
  @document = document
  @tag_list = tag_list
  @sources = sources
  @primary_source = primary_source
end

Public Instance Methods

==(another) click to toggle source
# File lib/yoda/store/objects/base.rb, line 86
def ==(another)
  eql?(another)
end
address() click to toggle source

@return [String]

# File lib/yoda/store/objects/base.rb, line 56
def address
  path
end
eql?(another) click to toggle source
# File lib/yoda/store/objects/base.rb, line 82
def eql?(another)
  self.class == another.class && to_h == another.to_h
end
hash() click to toggle source
# File lib/yoda/store/objects/base.rb, line 78
def hash
  ([self.class.name] + to_h.to_a).hash
end
kind() click to toggle source

@return [Symbol]

# File lib/yoda/store/objects/base.rb, line 51
def kind
  fail NotImplementedError
end
merge(another) click to toggle source

@param another [self] @return [self]

# File lib/yoda/store/objects/base.rb, line 74
def merge(another)
  self.class.new(merge_attributes(another))
end
name() click to toggle source

@return [String]

# File lib/yoda/store/objects/base.rb, line 46
def name
  fail NotImplementedError
end
to_h() click to toggle source

@return [Hash]

# File lib/yoda/store/objects/base.rb, line 61
def to_h
  {
    kind: kind,
    path: path,
    document: document,
    tag_list: tag_list,
    sources: sources,
    primary_source: primary_source
  }
end

Private Instance Methods

merge_attributes(another) click to toggle source

@param another [self] @return [Hash]

# File lib/yoda/store/objects/base.rb, line 94
def merge_attributes(another)
  {
    path: path,
    document: document + another.document,
    tag_list: tag_list + another.tag_list,
    sources: sources + another.sources,
    primary_source: primary_source || another.primary_source,
  }
end