Class: PasteHub::Util
- Inherits:
-
Object
- Object
- PasteHub::Util
- Defined in:
- lib/pastehub/util.rb
Instance Method Summary collapse
- #currentSeconds ⇒ Object
-
#currentTime ⇒ Object
return the currentTime in Unixtime.
- #diffList(list1, list2) ⇒ Object
-
#digest(str) ⇒ Object
return message digest for str.
-
#dropList(list1, num) ⇒ Object
Same as Gauche’s drop* function.
-
#initialize ⇒ Util
constructor
A new instance of Util.
-
#pulloutURL(str) ⇒ Object
pullout URL string from the string.
-
#stringLimit(str, limit) ⇒ Object
Cut string with limit characters.
-
#takeList(list1, num) ⇒ Object
Same as Gauche’s take* function.
Constructor Details
#initialize ⇒ Util
Returns a new instance of Util.
15 16 |
# File 'lib/pastehub/util.rb', line 15 def initialize() end |
Instance Method Details
#currentSeconds ⇒ Object
30 31 32 |
# File 'lib/pastehub/util.rb', line 30 def currentSeconds( ) self.key_seconds( self.currentTime() ) end |
#currentTime ⇒ Object
return the currentTime in Unixtime
24 25 26 27 28 |
# File 'lib/pastehub/util.rb', line 24 def currentTime( ) dt = Time.new.gmtime.to_datetime() currentDate = dt.strftime( "%s" ) + "=" + dt.strftime( "%F.%H:%M:%S" ) currentDate end |
#diffList(list1, list2) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/pastehub/util.rb', line 34 def diffList( list1, list2 ) set1 = Set.new set2 = Set.new list1.each { |e| set1.add(e) } list2.each { |e| set2.add(e) } set1.difference( set2 ).to_a end |
#digest(str) ⇒ Object
return message digest for str.
19 20 21 |
# File 'lib/pastehub/util.rb', line 19 def digest( str ) Digest::SHA1.hexdigest( str ) end |
#dropList(list1, num) ⇒ Object
Same as Gauche’s drop* function
54 55 56 57 58 59 60 61 62 |
# File 'lib/pastehub/util.rb', line 54 def dropList( list1, num ) if num < 0 list1 elsif num <= list1.size list1[ num .. list1.size ] else [] end end |
#pulloutURL(str) ⇒ Object
pullout URL string from the string
74 75 76 77 78 79 80 81 |
# File 'lib/pastehub/util.rb', line 74 def pulloutURL( str ) m = str.match( /(^|[\t\s])(http[s]?:\/\/[^\t\s]+)/ ) if m return m[2] else return nil end end |
#stringLimit(str, limit) ⇒ Object
Cut string with limit characters
65 66 67 68 69 70 71 |
# File 'lib/pastehub/util.rb', line 65 def stringLimit( str, limit ) if limit < str.size() str[0...(limit)] + "..." else str end end |
#takeList(list1, num) ⇒ Object
Same as Gauche’s take* function
43 44 45 46 47 48 49 50 51 |
# File 'lib/pastehub/util.rb', line 43 def takeList( list1, num ) if ( num < 0 ) list1 elsif num <= list1.size list1[ 0 ... num ] else list1 end end |