module Zakuro::Operation::MonthParser
MonthParser
月情報解析(yaml)
Public Class Methods
create_history_annnotations(history:, annotations: {}, relations: {})
click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 193 def self.create_history_annnotations(history:, annotations: {}, relations: {}) history_id = history.id history_annotations = [] [history_id, relations.fetch(history_id, '')].each do |id| add_annotation(history_annotations: history_annotations, annotations: annotations, id: id) end history_annotations end
load(yaml_hash: {})
click to toggle source
設定ファイルを読み込む
@param [Hash] yaml_hash 設定ファイルテキスト
@return [Array<MonthHistory>] 変更履歴
# File lib/zakuro/operation/month/parser.rb, line 132 def self.load(yaml_hash: {}) histories = create_histories(yaml_hash: yaml_hash) annotation_parser = AnnotationParser.new(yaml_hash: yaml_hash) annotation_parser.create add_annotations(histories: histories, annotation_parser: annotation_parser) end
run(filepath:)
click to toggle source
実行する
@return [Array<MonthHistory>] 変更履歴
# File lib/zakuro/operation/month/parser.rb, line 115 def self.run(filepath:) hash = YAML.load_file(filepath) failed = Validator.run(yaml_hash: hash) raise ArgumentError, failed.join("\n") unless failed.empty? load(yaml_hash: hash) end
Private Class Methods
add_annotation(history_annotations: [], annotations: {}, id: '')
click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 204 def self.add_annotation(history_annotations: [], annotations: {}, id: '') annotation = annotations.fetch(id, Annotation.new) return if annotation.invalid? history_annotations.push(annotation) end
add_annotations(annotation_parser:, histories: [])
click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 175 def self.add_annotations(annotation_parser:, histories: []) result = [] histories.each do |history| id = history.id result.push( MonthHistory.new( id: id, parent_id: history.parent_id, reference: history.reference, western_date: history.western_date, annotations: annotation_parser.specify(id: id), diffs: history.diffs ) ) end result end
create_histories(yaml_hash: {})
click to toggle source
変更履歴を読み込む
@param [Hash] yaml_hash 設定ファイルテキスト
@return [Array<MonthHistory>] 変更履歴
# File lib/zakuro/operation/month/parser.rb, line 148 def self.create_histories(yaml_hash: {}) result = [] yaml_hash.each do |month| next unless Operation::TypeParser.modified?(str: month['modified']) result.push( create_history(yaml_hash: month) ) end result end
create_history(yaml_hash: {})
click to toggle source
# File lib/zakuro/operation/month/parser.rb, line 161 def self.create_history(yaml_hash: {}) diffs = MonthDiffsParser.create(yaml_hash: yaml_hash['diffs']) western_date = Operation::TypeParser.western_date(str: yaml_hash['western_date']) reference = Reference.new(page: yaml_hash['page'].to_i, number: yaml_hash['number'].to_i, japan_date: yaml_hash['japan_date']) MonthHistory.new(id: yaml_hash['id'], parent_id: Operation::TypeParser.text(str: yaml_hash['parent_id']), reference: reference, western_date: western_date, diffs: diffs) end