class Zakuro::Operation::AnnotationParser

AnnotationParser 注釈解析

Attributes

annotations[R]

@return [Hash<String, Annotation>] 注釈

relations[R]

@return [Hash<String, String>] 関連注釈の対応関係

Public Class Methods

new(yaml_hash: {}) click to toggle source

初期化

@param [Hash] yaml_hash 設定ファイルテキスト

# File lib/zakuro/operation/month/parser.rb, line 227
def initialize(yaml_hash: {})
  @annotations = {}
  @relations = {}
  @yaml_hash = yaml_hash
end
resolve_history(hash: {}, annotations: {}, relations: {}) click to toggle source

月別履歴情報から注釈情報を取り出す

@param [<Type>] hash 月別履歴情報yaml @param [Hash<String, Annotation>] annotations 注釈 @param [Hash<String, String>] relations 関連注釈の対応関係

# File lib/zakuro/operation/month/parser.rb, line 251
def self.resolve_history(hash: {}, annotations: {}, relations: {})
  id = hash['id']
  annotations[id] = Annotation.new(
    id: id,
    description: Operation::TypeParser.text(str: hash['description']),
    note: Operation::TypeParser.text(str: hash['note'])
  )
  relation_id = hash['relation_id']

  return if Operation::TypeParser.invalid?(str: relation_id)

  relations[id] = relation_id
end

Public Instance Methods

create() click to toggle source

注釈を生成する

# File lib/zakuro/operation/month/parser.rb, line 236
def create
  @yaml_hash.each do |month|
    AnnotationParser.resolve_history(
      hash: month, annotations: @annotations, relations: @relations
    )
  end
end
specify(id: '') click to toggle source

注釈を特定する

@param [String] id ID

@return [Array<Annotation>] 注釈

# File lib/zakuro/operation/month/parser.rb, line 272
def specify(id: '')
  ids = [id, relations.fetch(id, '')]
  specify_by_ids(ids: ids)
end

Private Instance Methods

add_annotation(id: '', annotations: []) click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 288
def add_annotation(id: '', annotations: [])
  annotation = annotation(id: id)
  return if annotation.invalid?

  annotations.push(annotation)
end
annotation(id: '') click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 295
def annotation(id: '')
  @annotations.fetch(id, Annotation.new)
end
specify_by_ids(ids: []) click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 279
def specify_by_ids(ids: [])
  annotations = []
  ids.each do |id|
    add_annotation(id: id, annotations: annotations)
  end

  annotations
end