old 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31d234f6ffea0bff7c7dde9449280e871c35abf6
4
+ data.tar.gz: fc27c092868e8fc6f83f2148b636e8f3aa0fd548
5
+ SHA512:
6
+ metadata.gz: b098d71c6df88fed8342233bd991d8a304a511274e37425b01a6b191622d4f8ca4252077a105211d8017655844b775833ce02afff5d9075ab4b4ddd61890c831
7
+ data.tar.gz: 8bb0a918ee6e8795085f847402c952514b75817a836b5a4235dcf765674dd1a72c6334ac08e59eecccf65d8ad0046b5b6aa754e8758e0a045a430534e407fa71
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ /Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ ## Manpage:
38
+ *.[1-8]
39
+ *.[1-8].gz
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at 1995.hnagamin@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in old.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,117 @@
1
+ CC0 1.0 Universal
2
+
3
+ Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an "owner") of an original work of
8
+ authorship and/or a database (each, a "Work").
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific
12
+ works ("Commons") that the public can reliably and without fear of later
13
+ claims of infringement build upon, modify, incorporate in other works, reuse
14
+ and redistribute as freely as possible in any form whatsoever and for any
15
+ purposes, including without limitation commercial purposes. These owners may
16
+ contribute to the Commons to promote the ideal of a free culture and the
17
+ further production of creative, cultural and scientific works, or to gain
18
+ reputation or greater distribution for their Work in part through the use and
19
+ efforts of others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation
22
+ of additional consideration or compensation, the person associating CC0 with a
23
+ Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
+ and publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights ("Copyright and
31
+ Related Rights"). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+
34
+ i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
+ and translate a Work;
36
+
37
+ ii. moral rights retained by the original author(s) and/or performer(s);
38
+
39
+ iii. publicity and privacy rights pertaining to a person's image or likeness
40
+ depicted in a Work;
41
+
42
+ iv. rights protecting against unfair competition in regards to a Work,
43
+ subject to the limitations in paragraph 4(a), below;
44
+
45
+ v. rights protecting the extraction, dissemination, use and reuse of data in
46
+ a Work;
47
+
48
+ vi. database rights (such as those arising under Directive 96/9/EC of the
49
+ European Parliament and of the Council of 11 March 1996 on the legal
50
+ protection of databases, and under any national implementation thereof,
51
+ including any amended or successor version of such directive); and
52
+
53
+ vii. other similar, equivalent or corresponding rights throughout the world
54
+ based on applicable law or treaty, and any national implementations thereof.
55
+
56
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
+ unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
+ and Related Rights and associated claims and causes of action, whether now
60
+ known or unknown (including existing as well as future claims and causes of
61
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
+ duration provided by applicable law or treaty (including future time
63
+ extensions), (iii) in any current or future medium and for any number of
64
+ copies, and (iv) for any purpose whatsoever, including without limitation
65
+ commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
+ the Waiver for the benefit of each member of the public at large and to the
67
+ detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
+ shall not be subject to revocation, rescission, cancellation, termination, or
69
+ any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
+ by the public as contemplated by Affirmer's express Statement of Purpose.
71
+
72
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
73
+ judged legally invalid or ineffective under applicable law, then the Waiver
74
+ shall be preserved to the maximum extent permitted taking into account
75
+ Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
+ is so judged Affirmer hereby grants to each affected person a royalty-free,
77
+ non transferable, non sublicensable, non exclusive, irrevocable and
78
+ unconditional license to exercise Affirmer's Copyright and Related Rights in
79
+ the Work (i) in all territories worldwide, (ii) for the maximum duration
80
+ provided by applicable law or treaty (including future time extensions), (iii)
81
+ in any current or future medium and for any number of copies, and (iv) for any
82
+ purpose whatsoever, including without limitation commercial, advertising or
83
+ promotional purposes (the "License"). The License shall be deemed effective as
84
+ of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
+ License for any reason be judged legally invalid or ineffective under
86
+ applicable law, such partial invalidity or ineffectiveness shall not
87
+ invalidate the remainder of the License, and in such case Affirmer hereby
88
+ affirms that he or she will not (i) exercise any of his or her remaining
89
+ Copyright and Related Rights in the Work or (ii) assert any associated claims
90
+ and causes of action with respect to the Work, in either case contrary to
91
+ Affirmer's express Statement of Purpose.
92
+
93
+ 4. Limitations and Disclaimers.
94
+
95
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
+ surrendered, licensed or otherwise affected by this document.
97
+
98
+ b. Affirmer offers the Work as-is and makes no representations or warranties
99
+ of any kind concerning the Work, express, implied, statutory or otherwise,
100
+ including without limitation warranties of title, merchantability, fitness
101
+ for a particular purpose, non infringement, or the absence of latent or
102
+ other defects, accuracy, or the present or absence of errors, whether or not
103
+ discoverable, all to the greatest extent permissible under applicable law.
104
+
105
+ c. Affirmer disclaims responsibility for clearing rights of other persons
106
+ that may apply to the Work or any use thereof, including without limitation
107
+ any person's Copyright and Related Rights in the Work. Further, Affirmer
108
+ disclaims responsibility for obtaining any necessary consents, permissions
109
+ or other rights required for any use of the Work.
110
+
111
+ d. Affirmer understands and acknowledges that Creative Commons is not a
112
+ party to this document and has no duty or obligation with respect to this
113
+ CC0 or use of the Work.
114
+
115
+ For more information, please see
116
+ <http://creativecommons.org/publicdomain/zero/1.0/>
117
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Hideaki Nagamine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Old
2
+
3
+ man for SCP Database.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'old'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install old
20
+
21
+ ## Usage
22
+
23
+ $ old 173 <item #>
24
+
25
+ $ old -l <locale> <item #>
26
+
27
+ example:
28
+
29
+ $ old -l jp 173
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec old` to use the gem in this directory, ignoring other installed copies of this gem.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/1995hnagamin/old. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "old"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/old ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ script = File.expand_path('../old.sh', __FILE__)
4
+ exec "#{script} #{ARGV.join(' ')}"
data/exe/old.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ dir=`dirname $0`
4
+ path=`ruby $dir/../lib/old.rb $@`
5
+ man -l $path
data/lib/dom.rb ADDED
@@ -0,0 +1,27 @@
1
+ module OLD
2
+ module DOM
3
+ def is_text?(elem)
4
+ elem.text?
5
+ end
6
+
7
+ def is_elem?(elem)
8
+ elem.elem?
9
+ end
10
+
11
+ def text(elem)
12
+ elem.text
13
+ end
14
+
15
+ def children(elem)
16
+ elem.children
17
+ end
18
+
19
+ def xpath(elem, query)
20
+ elem.xpath(query)
21
+ end
22
+
23
+ def tag_name(elem)
24
+ elem.name
25
+ end
26
+ end
27
+ end
data/lib/locale.rb ADDED
@@ -0,0 +1,62 @@
1
+ module OLD
2
+ module SITE
3
+ CN = :cn
4
+ EN = :www
5
+ ES = :es
6
+ FR = :fr
7
+ JP = :ja
8
+ KO = :ko
9
+ PL = :pl
10
+ RU = :ru
11
+ TH = :th
12
+
13
+ def self.all
14
+ self.constants.map do |name|
15
+ self.const_get(name)
16
+ end
17
+ end
18
+
19
+ def self.create(obj)
20
+ map = {
21
+ "cn" => CN,
22
+ "en" => EN,
23
+ "es" => ES,
24
+ "fr" => FR,
25
+ "jp" => JP,
26
+ "ko" => KO,
27
+ "pl" => PL,
28
+ "ru" => RU,
29
+ "th" => TH
30
+ }
31
+ map[obj]
32
+ end
33
+ end
34
+
35
+ def get_endpoint(site)
36
+ case site
37
+ when SITE::CN
38
+ "www.scp-wiki-cn.org"
39
+ when SITE::ES
40
+ "lafundacionscp.wikidot.com"
41
+ when SITE::FR
42
+ "fondationscp.wikidot.com"
43
+ when SITE::PL, SITE::TH
44
+ "scp-#{site.to_s}.wikidot.com"
45
+ when SITE::RU
46
+ "scpfoundation.ru"
47
+ else
48
+ "#{site.to_s}.scp-wiki.net"
49
+ end
50
+ end
51
+
52
+ def get_locale(site)
53
+ case site
54
+ when SITE::CN
55
+ "zh_CN"
56
+ when SITE::EN
57
+ ""
58
+ else
59
+ site.to_s
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Old
2
+ VERSION = "0.1.0"
3
+ end
data/lib/old.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'set'
2
+ require 'pp'
3
+ require 'optparse'
4
+ require 'fileutils'
5
+ require_relative 'scp-article-loader'
6
+ require_relative 'roff-builder'
7
+ require_relative 'locale'
8
+
9
+ include OLD
10
+
11
+ begin
12
+ option = {
13
+ :locale => SITE::EN,
14
+ :manpath => File.expand_path("~/.old/man")
15
+ }
16
+ OptionParser.new do |opt|
17
+ opt.on('-l', '--locale=locale') do |locale|
18
+ option[:locale] = SITE.create(locale)
19
+ end
20
+ opt.parse! ARGV
21
+ end
22
+
23
+ article = ""
24
+ item_no = ARGV[0]
25
+ begin
26
+ subject = SCPArticleLoader.new(item_no, option)
27
+ builder = RoffBuilder.new(subject.article)
28
+ builder.title = "SCP-#{item_no}"
29
+ builder.section = 7
30
+ builder.date = Time.now
31
+ builder.source = "SCP Foundation"
32
+ builder.manual = "SCP Database"
33
+ builder.hr_width = `tput cols`.chomp.to_i
34
+ builder.name = subject.title
35
+ roff = builder.build
36
+ article = roff
37
+ rescue
38
+
39
+ article = <<-"EOS"
40
+ .TH "SCP-#{item_no}" 7 "#{Time.now.strftime("%Y-%m-%d")}" "SCP Foundation" "SCP Database"
41
+ .ce 1
42
+ [ACCESS DENIED]
43
+ .brp
44
+ EOS
45
+ end
46
+
47
+ path = "#{option[:manpath]}/#{get_locale(option[:locale])}/man7/"
48
+ FileUtils.mkdir_p(path) unless FileTest.exist?(path)
49
+ filepath = path + "scp-#{item_no}.7"
50
+ File.open(filepath, "w") do |file|
51
+ file.puts article
52
+ end
53
+
54
+ puts filepath
55
+ rescue OptionParser::InvalidOption
56
+ puts "invalid option"
57
+ end
@@ -0,0 +1,120 @@
1
+ require_relative 'dom'
2
+
3
+ module OLD
4
+ class RoffBuilder
5
+ include DOM
6
+ attr_accessor :title, :section, :date, :source, :manual,
7
+ :hr_width, :name
8
+ def initialize(elem)
9
+ @elem = elem
10
+ end
11
+
12
+ def build()
13
+ notable_tags =["p", "hr", "blockquote", "div/blockquote",
14
+ "br", "table"]
15
+ query = notable_tags.join('|')
16
+ paragraphs = xpath(@elem, query).map do |node|
17
+ html2roff(node)
18
+ end
19
+ body = paragraphs.join("")
20
+ <<-"EOS"
21
+ .TH "#{@title}" #{@section} "#{@date.strftime("%Y-%m-%d")}" "#{@source}" "#{@manual}"
22
+ .SH NAME
23
+ #{@name}
24
+
25
+ #{body}
26
+ EOS
27
+ end
28
+
29
+ def span2roff(e, child)
30
+ child
31
+ end
32
+
33
+ def is_section_title?(string)
34
+ # regard as a section title when:
35
+ # * inner text ends width ':'
36
+ # like "Description:", "Item #:" ...
37
+ # * inner text contains characteristic words
38
+ title_patterns = [
39
+ /^Item #:$/i,
40
+ /^Special Containment Procedures:$/i,
41
+ /^Object class:$/i,
42
+ /^Status/i,
43
+ /^Description:$/i,
44
+ /^[a-zA-Z ]*Log/i,
45
+ /^Addendum/i,
46
+ /^Appendix/i,
47
+ /^Notes [0-9]+/i,
48
+ /^Document.*[0-9]+/i
49
+ ]
50
+ title_patterns.any? {|pattern| string =~ pattern }
51
+ end
52
+
53
+ def table2roff(table)
54
+ rows = xpath("table, tr")
55
+ column = xpath(rows.first, "td").length
56
+ separater = "^"
57
+ content = rows.map { |tr|
58
+ row = xpath(tr, "td").map { |td|
59
+ elem2roff(td, false) + separater
60
+ }.join("")
61
+ }.join("\n")
62
+ <<EOS
63
+ .TS
64
+ tab(#{separater});
65
+ #{"l " * column }.
66
+ #{content}
67
+ .TE
68
+ EOS
69
+ end
70
+
71
+ def elem2roff(e, context)
72
+ ch_context = context
73
+ ch_context[:depth] = context[:depth] + 1
74
+ ch_context[:order] = -1
75
+ children = children(e).map do |ch|
76
+ ch_context[:order] += 1
77
+ html2roff(ch, ch_context)
78
+ end
79
+
80
+ depth = context[:depth]
81
+ order = context[:order]
82
+
83
+ case tag_name(e)
84
+ when "strong"
85
+ child = children.join("")
86
+ if depth <= 2 and is_section_title?(child) then
87
+ "\n.SH \"#{child.gsub(/:[ ]*$/, "") }\"\n"
88
+ elsif depth <= 2 and order == 0 then
89
+ "\n.SS \"#{child.gsub(/:[ ]*$/, "") }\"\n"
90
+ else
91
+ "\\fB#{child}\\fR"
92
+ end
93
+ when "br"
94
+ "\n.PP\n"
95
+ when "hr"
96
+ "\n.ce 1\n\\l'#{@hr_width / 4 * 3}'\n.ce 0\n"
97
+ when "blockquote"
98
+ ".RS\n" + children.join("") + "\n.RE\n"
99
+ when "p"
100
+ "\n.br\n#{children.join("").gsub(/^ /, "")}\n.br\n"
101
+ when "span"
102
+ child = children.join("")
103
+ span2roff(e, child)
104
+ when "table"
105
+ table2roff(e)
106
+ else
107
+ children.join("")
108
+ end
109
+ end
110
+
111
+ def html2roff(e, context = {:depth => 0, :order => 0})
112
+ if is_text?(e)
113
+ return text(e) + (text(e)[-1] == '.' ? " ": "")
114
+ else
115
+ elem2roff(e, context)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
@@ -0,0 +1,33 @@
1
+ require 'nokogiri'
2
+ require 'mechanize'
3
+ require_relative 'locale'
4
+
5
+ module OLD
6
+ class SCPArticleLoader
7
+ def initialize(item_no, option)
8
+ @item_no = item_no
9
+ @option = option
10
+ @agent = Mechanize.new
11
+ url = "http://#{get_endpoint(@option[:locale])}/scp-#{@item_no}"
12
+ page = @agent.get(url)
13
+ doc = Nokogiri::HTML(page.content.toutf8)
14
+ @article = doc.xpath('//*[@id="page-content"]').first
15
+ @title = nil
16
+ end
17
+
18
+ def title()
19
+ return @title if @title
20
+ series = @item_no.to_i / 1000 + 1
21
+ url = "http://www.scp-wiki.net/scp-series" +
22
+ (series > 1 ? "-#{series}" : "")
23
+ page = @agent.get(url)
24
+ doc = Nokogiri::HTML(page.content.toutf8)
25
+ article = doc.at('//*[@class="content-panel standalone series"]')
26
+ @title = article.text.match("SCP-#{@item_no} - (.*)$").to_s
27
+ end
28
+
29
+ def article()
30
+ return @article
31
+ end
32
+ end
33
+ end
data/old.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'old/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "old"
8
+ spec.version = Old::VERSION
9
+ spec.authors = ["Hideaki Nagamine"]
10
+ spec.email = ["1995.hnagamin@gmail.com"]
11
+
12
+ spec.summary = %q{CLI tool to view On-Line Document for contained objects.}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/1995hnagamin/old"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "nokogiri", "~> 1.6.7"
23
+ spec.add_dependency "mechanize", "~> 2.7.3"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: old
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hideaki Nagamine
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: mechanize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.7.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: ''
84
+ email:
85
+ - 1995.hnagamin@gmail.com
86
+ executables:
87
+ - old
88
+ - old.sh
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - exe/old
104
+ - exe/old.sh
105
+ - lib/dom.rb
106
+ - lib/locale.rb
107
+ - lib/old.rb
108
+ - lib/old/version.rb
109
+ - lib/roff-builder.rb
110
+ - lib/scp-article-loader.rb
111
+ - old.gemspec
112
+ homepage: https://github.com/1995hnagamin/old
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: CLI tool to view On-Line Document for contained objects.
136
+ test_files: []