pion 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/pion.rb +41 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 419ed957397c6a0e9c837a01aea0b3dbef96069c
|
4
|
+
data.tar.gz: 71570724f2a77cb4236525edbd7ded1a3ba4073d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 434ba66dd46b37da20c5296d5e16cea37b2ac672abdd6ab3efe32d99e78c9ba7f1358e3a13fe55e3552aafe27e1002821e8b411315e3db57f0a8d975bc1851ea
|
7
|
+
data.tar.gz: 70370dca9cba835473a71dcf6118fbb3b1d0709ccb5fcf356c0322d3d782e75da09ada6e57014d61bb4e59b8bab370110cb30b506ddb199639d61cfd39a9ab24
|
data/lib/pion.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class Pion
|
2
|
+
# Version number for Pion
|
3
|
+
VERSION = "0.1.0"
|
4
|
+
|
5
|
+
# Initialize a new Pion object
|
6
|
+
def initialize(directory, extension = "html")
|
7
|
+
raise ArgumentError, "Extension name must be a string." unless extension.is_a? String
|
8
|
+
|
9
|
+
@directory = method(:get_directory).call directory
|
10
|
+
@extension = extension.gsub /\A\./, ""
|
11
|
+
end
|
12
|
+
|
13
|
+
# Generate urls from files
|
14
|
+
def generate
|
15
|
+
urls = []
|
16
|
+
|
17
|
+
Dir.glob "#{@directory}/**/*.#{@extension}" do |file|
|
18
|
+
urls << {file: file, url: method(:get_url).call(file)} unless file == "." or file == ".."
|
19
|
+
end
|
20
|
+
|
21
|
+
urls
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Get directory or raise errors if it's faulty
|
27
|
+
def get_directory(directory)
|
28
|
+
return directory if directory.is_a? String and File.directory? directory
|
29
|
+
|
30
|
+
raise ArgumentError, "Directory name must be a string." unless directory.is_a? String
|
31
|
+
raise ArgumentError, "Directory must be a valid directory." unless File.directory? directory
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convert filename to clean url
|
35
|
+
def get_url(file)
|
36
|
+
url = file.gsub /\A#{@directory}/, ""
|
37
|
+
url = url.gsub /(\/index)?\.#{@extension}\z/, ""
|
38
|
+
|
39
|
+
url == "" ? "/" : url
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oscar Palmér
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A tiny gem for generating urls for files.
|
14
|
+
email: opalmer@me.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/pion.rb
|
20
|
+
homepage: http://git.io/pion
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Pion!
|
44
|
+
test_files: []
|