Class: Arkrb::Mod

Inherits:
Object
  • Object
show all
Defined in:
lib/arkrb/server/mod.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod_id) ⇒ Mod

Returns a new instance of Mod.



6
7
8
9
10
11
12
13
14
15
# File 'lib/arkrb/server/mod.rb', line 6

def initialize(mod_id)
  @id = mod_id.to_i
  @workshop_url = "https://steamcommunity.com/sharedfiles/filedetails/?id=#{mod_id}"
  @changelog_url = "https://steamcommunity.com/sharedfiles/filedetails/changelog/#{mod_id}"

  does_mod_exist?

  @name = update_mod_name
  @version_tag = latest_version_tag
end

Instance Attribute Details

#changelog_urlObject (readonly)

Returns the value of attribute changelog_url.



17
18
19
# File 'lib/arkrb/server/mod.rb', line 17

def changelog_url
  @changelog_url
end

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/arkrb/server/mod.rb', line 17

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/arkrb/server/mod.rb', line 17

def name
  @name
end

#version_tagObject (readonly)

Returns the value of attribute version_tag.



17
18
19
# File 'lib/arkrb/server/mod.rb', line 17

def version_tag
  @version_tag
end

#workshop_urlObject (readonly)

Returns the value of attribute workshop_url.



17
18
19
# File 'lib/arkrb/server/mod.rb', line 17

def workshop_url
  @workshop_url
end

Instance Method Details

#does_mod_exist?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/arkrb/server/mod.rb', line 35

def does_mod_exist?
  document = Oga.parse_html(open(workshop_url))
  if document.at_css('div[class="error_ctn"] h3').text == 'That item does not exist.  It may have been removed by the author.'
    raise Arkrb::Error::ModDoesNotExist, "Woah the mod #{id} does not exist!"
  end
rescue NoMethodError
  true
end

#latest_version_tagObject



29
30
31
32
33
# File 'lib/arkrb/server/mod.rb', line 29

def latest_version_tag
  document = Oga.parse_html(open(changelog_url))
  version = document.at_css('div[class~="workshopAnnouncement"]:nth-child(3) > div[class="headline"]').text.strip
  Digest::MD5.hexdigest(version).strip
end

#to_hObject Also known as: to_hash



44
45
46
47
48
49
50
51
52
# File 'lib/arkrb/server/mod.rb', line 44

def to_h
  {
      id: id,
      name: name,
      version_tag: version_tag,
      workshop_url: workshop_url,
      changelog_url: changelog_url
  }
end

#update_infoObject



19
20
21
22
# File 'lib/arkrb/server/mod.rb', line 19

def update_info
  self.name = update_mod_name
  self.version = latest_version_tag
end

#update_mod_nameObject



24
25
26
27
# File 'lib/arkrb/server/mod.rb', line 24

def update_mod_name
  document = Oga.parse_html(open(changelog_url))
  document.at_css('div[class="workshopItemTitle"]').text
end