diff options
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Gemfile.lock | 15 | ||||
-rw-r--r-- | ramaskrik-program.rb | 23 |
3 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,4 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem "nokogiri" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d6f0963 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.3.0) + nokogiri (1.8.4) + mini_portile2 (~> 2.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri + +BUNDLED WITH + 1.16.1 diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb new file mode 100644 index 0000000..0ca62e2 --- /dev/null +++ b/ramaskrik-program.rb @@ -0,0 +1,23 @@ +require 'date' +require 'nokogiri' +require 'open-uri' + +class Movie + attr_reader :title, :start_time, :end_time, :venue + + def initialize(node) + @title = node.css("h4").text.strip + @start_time = DateTime.parse(node.css(".date").attribute('title').value) + @end_time = DateTime.parse(@start_time.strftime('%F') + node.css(".prgtype-endTime").text.strip.sub(/\w+/, '')) + @end_time += 1 if @end_time < @start_time + @venue = node.css(".place").text.strip + end + + def to_s + "#{title} #{start_time} - #{end_time}, #{venue}" + end +end + +doc = Nokogiri::HTML(open("program.html")) ## open("https://ramaskrik.no/program/")) +movies = doc.css(".kultur-type-movie").map { |movie| Movie.new(movie) } +puts movies |