Class: ContributorsStats::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/contributors_stats/formatter.rb,
lib/plugins/contributors_stats/formatter/html.rb

Overview

Takes care of formatting data and saving it

Defined Under Namespace

Classes: Html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, type = :html, options = {}) ⇒ Formatter

Returns a new instance of Formatter.



11
12
13
# File 'lib/contributors_stats/formatter.rb', line 11

def initialize(data, type = :html, options = {})
   format(data, type, options)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/contributors_stats/formatter.rb', line 9

def content
  @content
end

Instance Method Details

#save(*targets) ⇒ Object

overwrite target with the formatted content

Parameters:

  • targets (Array)

    list of files to overwrite



17
18
19
20
21
# File 'lib/contributors_stats/formatter.rb', line 17

def save(*targets)
  targets.flatten.each do |file|
    File.open(file, 'w') { |f| f.write(content * "\n") }
  end
end

#update(*targets, options: {}) ⇒ Object

update target with the formatted content

Parameters:

  • targets (Array)

    list of files to update

  • options (Hash) (defaults to: {})

    options are passed to updater plugin, check



26
27
28
29
30
31
32
33
# File 'lib/contributors_stats/formatter.rb', line 26

def update(*targets, options: {})
  targets.flatten.each do |file|
    plugin = plugins.first_ask!("updater", :handles?, file)
    update_file(file) do |file_content|
      plugin.update(file_content, content, options)
    end
  end
end