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



63
64
65
66
67
68
69
70
# File 'lib/pdd.rb', line 63

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.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pdd.rb', line 73

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