Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/gslide/models/presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class Presentation

attr_reader :id

def initialize(id, auth: nil)
@id = id
PRESENTATION_PATTERN = %r[/presentation/d/([a-zA-Z0-9\-_]+)?]

def initialize(id_or_url, auth: nil)
@id = (url_id = id_or_url.match(PRESENTATION_PATTERN)) ? url_id[1] : id_or_url
@auth = auth
end

Expand Down
16 changes: 13 additions & 3 deletions test/test_gslide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ def test_that_it_has_a_version_number
refute_nil ::Gslide::VERSION
end

# def test_it_does_something_useful
# assert false
# end
def test_initialized_presentation_with_url
url = "https://docs.google.com/presentation/d/1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8/edit?usp=sharing"

presentation = Gslide::Presentation.new(url, auth: nil)
assert_equal "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8", presentation.id
end

def test_initialized_with_presentation_id
presentation_id = "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8"

presentation = Gslide::Presentation.new(presentation_id, auth: nil)
assert_equal "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8", presentation.id
end
end