Class: Slapp::Parser

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/slapp/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#convert_to_bytes

Constructor Details

#initialize(path, slackware_version) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
10
# File 'lib/slapp/parser.rb', line 6

def initialize(path, slackware_version)
  @lines = File.readlines(path, :encoding => 'ISO-8859-1')
  @contents = @lines.join('')
  @slackware_version = slackware_version
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



4
5
6
# File 'lib/slapp/parser.rb', line 4

def contents
  @contents
end

#linesObject

Returns the value of attribute lines.



4
5
6
# File 'lib/slapp/parser.rb', line 4

def lines
  @lines
end

#slackware_versionObject

Returns the value of attribute slackware_version.



4
5
6
# File 'lib/slapp/parser.rb', line 4

def slackware_version
  @slackware_version
end

Instance Method Details

#packagesObject



24
25
26
27
28
# File 'lib/slapp/parser.rb', line 24

def packages
  raw_packages.map { |pkg|
    Slapp::Package.new pkg.first, slackware_version
  }
end

#total_size_compressedObject



18
19
20
21
22
# File 'lib/slapp/parser.rb', line 18

def total_size_compressed
  line = lines.select { |line| line =~ total_size_regex('compressed') }
  match = total_size_regex('compressed').match(line.first)
  convert_to_bytes match[1]
end

#total_size_uncompressedObject



12
13
14
15
16
# File 'lib/slapp/parser.rb', line 12

def total_size_uncompressed
  line = lines.select { |line| line =~ total_size_regex('uncompressed') }
  match = total_size_regex('uncompressed').match(line.first)
  convert_to_bytes match[1]
end