Class: PDD::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pdd.rb

Overview

Code base abstraction

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Base

Ctor.

opts

Options



80
81
82
83
84
85
86
87
# File 'lib/pdd.rb', line 80

def initialize(opts)
  @opts = opts
  PDD.opts = opts
  PDD.log.level = Logger::INFO if @opts[:verbose]
  PDD.log.level = Logger::ERROR if @opts[:quiet]
  PDD.log.info "My version is #{PDD::VERSION}"
  PDD.log.info "Ruby version is #{RUBY_VERSION} at #{RUBY_PLATFORM}"
end

Instance Method Details

#xmlObject

Generate XML.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pdd.rb', line 90

def xml
  dir = @opts[:source] || Dir.pwd
  PDD.log.info "Reading from root dir #{dir}"
  require_relative 'pdd/sources'
  sources = Sources.new(File.expand_path(dir))
  sources.exclude((@opts[:exclude] || []) + (@opts['skip-gitignore'] || []))
  sources.include(@opts[:include])
  sanitize(
    rules(
      Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
        xml << "<?xml-stylesheet type='text/xsl' href='#{xsl}'?>"
        xml.puzzles(attrs) do
          sources.fetch.each do |source|
            source.puzzles.each do |puzzle|
              PDD.log.info "Puzzle #{puzzle.props[:id]} " \
                "#{puzzle.props[:estimate]}/#{puzzle.props[:role]}" \
                " at #{puzzle.props[:file]}"
              render puzzle, xml
            end
          end
        end
      end.to_xml
    )
  )
end