class Devist::Parser

parser.rb This file is a part of the devist package. Halis Duraki <duraki.halis@nsoft.ba>

Parser will allow a building routine for the given changelog by investigating every line in the file. The Parser created project info, and build changelog, but it also check if the given file is proper devist format.

Attributes

changelog[R]
project[R]

Public Instance Methods

build_changelog(line) click to toggle source

Changelog builder.

# File lib/devist/parser.rb, line 32
def build_changelog(line)
  build_version(line)
  build_tags(line)
end
build_info(line) click to toggle source

Project builder.

# File lib/devist/parser.rb, line 17
def build_info(line)
  case line
  when /@project:+/
    @project.name = Devist::Extractor.extract_info(line)
    print "  * Extracting project name ... [#{@project.name.chomp.strip!}]\n"
  when /@author:.+/
    @project.author = Devist::Extractor.extract_info(line)
    print "  * Extracting project author ... [#{@project.author.chomp.strip!}]\n"
  when /@homepage:.+/
    @project.homepage = Devist::Extractor.extract_info(line)
    print "  * Extracting project homepage ... [#{@project.homepage.chomp.strip!}]\n"
  end
end
build_tags(line) click to toggle source

Build tags.

# File lib/devist/parser.rb, line 38
def build_tags(line)
  case line
  when /#added.+/
    @changelog[@version].tag 'added', Devist::Extractor.extract_change(line)
  when /#fixed.+/
    @changelog[@version].tag 'fixed', Devist::Extractor.extract_change(line)
  when /#removed.+/
    @changelog[@version].tag 'removed', Devist::Extractor.extract_change(line)
  when /#improved.+/
    @changelog[@version].tag 'improved', Devist::Extractor.extract_change(line)
  end
end
build_version(line) click to toggle source

Build version.

# File lib/devist/parser.rb, line 52
def build_version(line)
  case line
    when /### Version+/
    @date = Date.parse(line) # Extract version date
    @version += 1 # Increment version
    @changelog[@version] = Devist::Version.new (Devist::Extractor.extract_version line), @date
  end
end
devist?(file_name) click to toggle source

Is file devist configured.

# File lib/devist/parser.rb, line 62
def devist?(file_name)
  is_devist = File.open(file_name).to_a

  if is_devist.last.equal?("")
    is_devist.pop is_devist.last
  end

  print "  * Checking if changelog is devist configured ...\n"
  if is_devist.last.chomp != '.devist'
    print "  * The file is not configured for devist. Are you missing .devist at the end of the file?\n"
    print "  * Skipping ...\n"
  end

  print "  * Found .devist signature.\n"
end
parse_data(file_name) click to toggle source

Line parser.

# File lib/devist/parser.rb, line 79
def parse_data(file_name)
  @project = Devist::Project.new
  @changelog = []
  @version = -1 # Start from 0

  devist?(file_name) # Check if file is configured for usage

  print "  * Building model from file data ...\n"

  File.foreach(file_name) do |line|
    build_info(line) # Build project info
    build_changelog(line) # Build changelog data
  end

  @changelog
end