-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored torrent class using rt conversion methods
rTorrent provides a bunch of conversion methods which removed the need to be converting file size, dates and time. Attribute builder now uses these to do automatic conversion and creating a _raw attribute for each of those fields converted.
- Loading branch information
1 parent
adb8d61
commit 8fd71bf
Showing
6 changed files
with
107 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Retort::Conversion | ||
|
||
|
||
class Call | ||
TYPES = { time: 'to_time', date: 'to_date', size: 'to_xb' } | ||
attr_accessor :attributes | ||
|
||
def initialize(prefix) | ||
@attributes = {} | ||
@prefix = prefix | ||
end | ||
|
||
def method_missing(*args, &block) | ||
property = args.shift | ||
options = args.shift || {} | ||
|
||
type = options[:type] | ||
method_name = options[:name] || property | ||
method_name = "#{@prefix}.#{method_name}" unless @prefix.empty? | ||
|
||
if TYPES.member? type | ||
#Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'. | ||
@attributes[property] = "#{TYPES[type]}=$#{method_name}" | ||
property = "#{property}_raw" | ||
end | ||
@attributes[property] = method_name | ||
end | ||
end | ||
|
||
def build(prefix="") | ||
c = Call.new prefix | ||
yield c | ||
c.attributes | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
class Fixnum | ||
def bytes | ||
self | ||
def truth | ||
return [false,true][self] if (0..1).member? self | ||
end | ||
|
||
def kilobytes | ||
bytes / 1024.0 | ||
end | ||
|
||
def kbs | ||
"#{sprintf('%.2f', kilobytes)}KB/s" | ||
end | ||
|
||
def megabytes | ||
kilobytes / 1024.0 | ||
end | ||
|
||
end | ||
|
||
class Float | ||
def percent | ||
def percent_raw | ||
(self * 100).to_i | ||
end | ||
end | ||
|
||
def fmt | ||
"#{sprintf('%.2f', self)}" | ||
def percent | ||
"#{sprintf('%.2f', percent_raw)}" | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
module Retort | ||
module Retort | ||
|
||
class Config | ||
attr_accessor :url | ||
end | ||
|
||
class Service | ||
|
||
class << self | ||
|
||
def configure | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Retort | ||
VERSION = "0.0.3" | ||
VERSION = "0.0.4" | ||
end |