Class: Devist::Parser

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

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#changelogObject (readonly)

Returns the value of attribute changelog



14
15
16
# File 'lib/devist/parser.rb', line 14

def changelog
  @changelog
end

#projectObject (readonly)

Returns the value of attribute project



14
15
16
# File 'lib/devist/parser.rb', line 14

def project
  @project
end

Instance Method Details

#build_changelog(line) ⇒ Object

Changelog builder.



32
33
34
35
# File 'lib/devist/parser.rb', line 32

def build_changelog(line)
  build_version(line)
  build_tags(line)
end

#build_info(line) ⇒ Object

Project builder.



17
18
19
20
21
22
23
24
25
26
27
28
29
# 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) ⇒ Object

Build tags.



38
39
40
41
42
43
44
45
46
47
48
49
# 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) ⇒ Object

Build version.



52
53
54
55
56
57
58
59
# 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) ⇒ Boolean

Is file devist configured.

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object

Line parser.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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