diff --git a/lib/music.rb b/lib/music.rb index 946e45d344e69da36d83282a58e2bf75d6fe7a65..cd1520230561f38cb8abb2cacacd0a243594c843 100644 --- a/lib/music.rb +++ b/lib/music.rb @@ -5,11 +5,11 @@ require 'active_record' # Music Object # # Its attribut are : -# * title -# * author -# * url -# * sender -# * file -# * created_ad +# * title +# * author +# * url +# * sender +# * file +# * created_ad class Music < ActiveRecord::Base end diff --git a/lib/tag.rb b/lib/tag.rb index e92b89754eabe3fb0a6ce1ef9e1bb00de6d884eb..d850b5ec19286438f066f9b6b83ce565a2da0569 100644 --- a/lib/tag.rb +++ b/lib/tag.rb @@ -5,7 +5,7 @@ require 'active_record' # Tag Object # # Its attribute are : -# * video -# * tage +# * video +# * tage class Tag < ActiveRecord::Base end diff --git a/lib/tag_parser.rb b/lib/tag_parser.rb new file mode 100644 index 0000000000000000000000000000000000000000..c9021557eea4fa56b3f406db59e6d29c730d88b0 --- /dev/null +++ b/lib/tag_parser.rb @@ -0,0 +1,21 @@ +# Parse a text and extract tags. +# +# A tag starts with a "#" and can contains the following characters : [a-zA-Z0-9_-]. +class TagParser + # Parse a text and extract tags. + # + # * *Args*: + # - +text+: the text to parse + # + # * *Returns*: + # - an array containing the tags + def self.parse! (text) + tags = [] + + text.gsub(/(#[a-zA-Z0-9_-]*)/).each do |tag| + tags << tag + end + + return tags + end +end diff --git a/spec/tag_parser_spec.rb b/spec/tag_parser_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..fb11ae03c13b6aa4ef202068dbce0e2831f0d015 --- /dev/null +++ b/spec/tag_parser_spec.rb @@ -0,0 +1,10 @@ +require_relative '../lib/tag_parser.rb' + +describe TagParser do + describe :parse! do + it 'return tags in a text given' do + tags = TagParser.parse! "hey #i contain #two tags !" + tags.should == ["#i", "#two"] + end + end +end