Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
1. Блоки, лямбды, проки.
1. Гемы.
1. Метапрограммирование.

Binary file added converter/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions converter/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in converter.gemspec
gemspec
20 changes: 20 additions & 0 deletions converter/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PATH
remote: .
specs:
converter (0.1.0)

GEM
remote: https://rubygems.org/
specs:
rake (10.5.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.17)
converter!
rake (~> 10.0)

BUNDLED WITH
1.17.3
21 changes: 21 additions & 0 deletions converter/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 TODO: Write your name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
39 changes: 39 additions & 0 deletions converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Converter

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/converter`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'converter'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install converter

## Usage

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

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).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/converter.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
2 changes: 2 additions & 0 deletions converter/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"
task :default => :spec
Binary file added converter/bin/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions converter/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "converter"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions converter/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
38 changes: 38 additions & 0 deletions converter/converter.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "converter/version"

Gem::Specification.new do |spec|
spec.name = "converter"
spec.version = Converter::VERSION
spec.authors = ["@egorles"]

spec.summary = %q{Converter from RSS/ATOM/JSON to RSS/ATOM/JSON}
spec.homepage = "https://github.com/egorles"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage

else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rake", "~> 10.0"
end
49 changes: 49 additions & 0 deletions converter/exe/converter
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "converter"
require "optparse"

options = {}

gem_spec = Gem::Specification::load("converter.gemspec")

parser = OptionParser.new do |opt|
opt.banner = "Usage #{gem_spec.name} [options]"
opt.define_head gem_spec.summary

opt.separator ""

opt.on("-i", "--input [url]", String) do |input|
options[:input] = input
end
opt.on("-o", "--output-format [rss | json | atom]", String) do |output|
options[:output] = output
end
opt.on("-s", "--sort [asc | desc]", String) do |sort|
options[:sort] = sort
end
opt.on("-f", "--file-name [string]", String) do |file|
options[:file] = file
end

opt.separator ""

opt.on("-h", "--help", "Show this message") do |help|
puts opt
exit
end
end

begin
parser.parse!
puts "The result is %s" % Converter.convert(options)

rescue OptionParser::InvalidArgument => e
STDERR.puts %Q[#{e.message.capitalize}. Run "#{File.basename($0)}" --help for details.]
exit 1
rescue KeyError
STDERR.puts %Q[Insufficient arguments. Run "#{File.basename($0)}" --help for details.]
exit 2
end

Binary file added converter/lib/.DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions converter/lib/converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "converter/version"
require 'rss'
require 'json'



module Converter
class Error < StandardError; end
# Your code goes here...

def self.convert (options = {})
input = options.fetch(:input)
output = options.fetch(:output)
sort = options.fetch(:sort)
file = options.fetch.(:file)

if (input.include? 'rss')
rss_read (input)
elsif (input.include? 'json')
json_read (input)
elsif (input.include? 'atom')
atom_read (input)
end

end

def self.rss_read (input)
url = "#{input}"
open(url) do |rss|
feed = RSS::Parser.parse(rss)
puts feed
end
end

def self.json_read (input)
file = File.read(input)
end
end
3 changes: 3 additions & 0 deletions converter/lib/converter/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Converter
VERSION = "0.1.0"
end