Class: RuAUR::Package

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, repo = "aur") ⇒ Package

Returns a new instance of Package.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruaur/package.rb', line 59

def initialize(json, repo = "aur")
    @description = json["Description"]
    @description ||= ""
    @installed = nil
    @json = json
    @name = json["Name"]
    @repo = repo
    if (json["URLPath"])
        @url = "https://aur.archlinux.org#{json["URLPath"]}"
    else
        @url = nil
    end
    @version = json["Version"]
    @votes = nil
    @votes = "(#{json["NumVotes"]})" if (json["NumVotes"])
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/ruaur/package.rb', line 4

def description
  @description
end

#installed(version = nil) ⇒ Object

Returns the value of attribute installed.



5
6
7
# File 'lib/ruaur/package.rb', line 5

def installed
  @installed
end

#jsonObject

Returns the value of attribute json.



6
7
8
# File 'lib/ruaur/package.rb', line 6

def json
  @json
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/ruaur/package.rb', line 7

def name
  @name
end

#repoObject

Returns the value of attribute repo.



8
9
10
# File 'lib/ruaur/package.rb', line 8

def repo
  @repo
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/ruaur/package.rb', line 9

def url
  @url
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/ruaur/package.rb', line 10

def version
  @version
end

#votesObject

Returns the value of attribute votes.



11
12
13
# File 'lib/ruaur/package.rb', line 11

def votes
  @votes
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruaur/package.rb', line 13

def <=>(other)
    if (self.name.downcase == other.name.downcase)
        self_version = self.version.split(/\D+/).map(&:to_i)
        other_version = self.version.split(/\D+/).map(&:to_i)

        [self_version.size, other_version.size].max.times do |i|
            cmp = self_version[i] <=> other_version[i]
            return cmp if (cmp != 0)
        end
    end
    return (self.name.downcase <=> other.name.downcase)
end

#newer?(ver) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ruaur/package.rb', line 81

def newer?(ver)
    pkg_version = @version.split(/\D+/).map(&:to_i)
    installed_version = ver.split(/\D+/).map(&:to_i)

    [pkg_version.size, installed_version.size].max.times do |i|
        return false if (pkg_version[i].nil?)
        return true if (installed_version[i].nil?)
        return true if (pkg_version[i] > installed_version[i])
        return false if (pkg_version[i] < installed_version[i])
    end
    return false
end

#older?(version) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ruaur/package.rb', line 94

def older?(version)
    pkg_version = @version.split(/\D+/).map(&:to_i)
    installed_version = version.split(/\D+/).map(&:to_i)

    [pkg_version.size, installed_version.size].max.times do |i|
        return true if (pkg_version[i].nil?)
        return false if (installed_version[i].nil?)
        return true if (pkg_version[i] < installed_version[i])
        return false if (pkg_version[i] > installed_version[i])
    end
    return false
end

#tarball(file) ⇒ Object



107
108
109
# File 'lib/ruaur/package.rb', line 107

def tarball(file)
    return RuAUR::AUR.tarball(@url, file)
end

#to_sObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ruaur/package.rb', line 111

def to_s
    out = Array.new
    out.push(
        hilight_header(
            @repo,
            @name,
            @installed,
            @version,
            @votes
        )
    )

    # Wrap at default minus 4 spaces
    @description.scan(/\S.{0,76}\S(?=\s|$)|\S+/).each do |l|
        out.push("    #{l.strip}")
    end

    return out.join("\n")
end