From 9e5b636eb8b61ec866137eaa6ecc4403b0ce935d Mon Sep 17 00:00:00 2001 From: talaatmagdyx Date: Sun, 2 Jul 2023 11:23:12 +0300 Subject: [PATCH] updated documentations and improve tests --- .github/CODE_OF_CONDUCT.md | 2 +- .github/CONTRIBUTING.md | 2 +- README.md | 66 ++++++++++++++++++++++++++++++++-- lib/socials_regex/platforms.rb | 4 +++ sig/socials_regex/regexes.rbs | 2 ++ 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index bda8231..555e8dc 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@lokalise.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at talaatmagdy75@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 573cc0c..75c83fe 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -9,6 +9,6 @@ 7. Commit and push your changes. 8. [Submit a pull request.][pr] -[fork]: http://help.github.com/fork-a-repo/ +[fork]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks [branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches [pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests \ No newline at end of file diff --git a/README.md b/README.md index 0df106a..06a90bf 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,64 @@ This gem requires Ruby 2.6+ ## Usage -TODO: Write usage instructions here +```ruby +require 'socials_regex' + +supported_platforms = SocialsRegex::Platforms.all +# [:PLATFORM_FACEBOOK, :PLATFORM_GITHUB, :PLATFORM_LINKEDIN, :PLATFORM_TWITTER, :PLATFORM_INSTAGRAM, :PLATFORM_YOUTUBE, +# :PLATFORM_EMAIL, :PLATFORM_HACKER_NEWS, :PLATFORM_MEDIUM, :PLATFORM_PHONE, :PLATFORM_REDDIT, +# :PLATFORM_SKYPE, :PLATFORM_SNAPCHAT, :PLATFORM_STACKEXCHANGE, :PLATFORM_STACKOVERFLOW, :PLATFORM_STACKOVERFLOW, +# :PLATFORM_TELEGRAM, :PLATFORM_VIMEO, :PLATFORM_XING, :PLATFORM_ANGELLIST, :PLATFORM_CRUNCHBASE, +# :PLATFORM_STACKEXCHANGE_NETWORK, :PLATFORM_WHATSAPP, :PLATFORM_YELP] + + +supported_regexes = SocialsRegex::Regexes.all +# [:ANGELLIST_URL_REGEX, :CRUNCHBASE_URL_REGEX, :EMAIL_URL_REGEX, :FACEBOOK_URL_REGEX, :GITHUB_URL_REGEX, :HACKERNEWS_URL_REGEX, +# :INSTAGRAM_URL_REGEX, :LINKEDIN_URL_REGEX, :MEDIUM_URL_REGEX, :PHONE_URL_REGEX, :REDDIT_URL_REGEX, :SKYPE_URL_REGEX, :SNAPCHAT_URL_REGEX, +# :STACKEXCHANGE_URL_REGEX, :STACKEXCHANGE_NETWORK_URL_REGEX, :STACKOVERFLOW_URL_REGEX, :TELEGRAM_URL_REGEX, :TWITTER_URL_REGEX, +# :VIMEO_URL_REGEX, :XING_URL_REGEX, :YOUTUBE_URL_REGEX, :WHATSAPP_URL_REGEX, :YELP_URL_REGEX] + +# get all regex for all regex +platform_regexes = SocialsRegex::Socials::PLATFORMS_REGEX +# example [:yelp, {:company=>/(?:https?:\/\/)?(?:www\.)?yelp\.com\/biz\/(?[A-Za-z0-9_-]+)/}] + +# get regex for specific platforms +twitter_regex = SocialsRegex::Socials::PLATFORMS_REGEX[:twitter] +# {:status=>/(?:https?:)?\/\/(?:[A-Za-z]+\.)?twitter\.com\/@?(?[A-Za-z0-9_]+)\/status\/(?[0-9]+)\/?/, +# :user=>/(?:https?:)?\/\/(?:[A-Za-z]+\.)?twitter\.com\/@?(?!home|share|privacy|tos)(?[A-Za-z0-9_]+)\/?/} + + +# how to extract social data from links or texts +text = 'https://twitter.com/karllorey/status/1259924082067374088' \ + 'https://twitter.com/karllorey12/status/12599240820673740883' \ + 'http://crunchbase.com/organization/acme-corp jeff@amazon.com mailto:plususer+test@gmail.com' \ + 'https://facebook.com/peter.parker https://www.facebook.com/profile.php?id=100004123456789' \ + 'https://github.com/talaatmagdyx https://github.com/talaatmagdyx/socials_regex' \ + 'https://news.ycombinator.com/item?id=23290375 https://instagram.com/__disco__dude' \ + 'https://www.linkedin.com/in/talaatmagdyx/ https://medium.com/does-exist/some-post-123abc' +extract = SocialsRegex::Extraction.new(text: text) +# # + +# to extract all links and data +extract.extract_matches_per_platform +# {:crunchbase=>{:company=>[{:matched=>"http://crunchbase.com/organization/acme-corp", "organization"=>"acme-corp"}]}, +# :medium=>{:post=>[{:matched=>"https://medium.com/does-exist/some-post-123abc", "username"=>nil, "publication"=>"does-exist", "slug"=>"some-post", "post_id"=>"123abc"}]}, +# :hackernews=>{:item=>[{:matched=>"https://news.ycombinator.com/item?id=23290375", "item"=>"23290375"}]}, +# :email=>{:email=>[{:matched=>"jeff@amazon.com", "email"=>"jeff@amazon.com"}, {:matched=>"mailto:plususer+test@gmail.comhttps", "email"=>"plususer+test@gmail.comhttps"}]}, +# :instagram=>{:profile=>[{:matched=>"https://instagram.com/__disco__dudehttps", "username"=>"__disco__dudehttps"}]}, + + +# to extract links or data using specific platform like instagram +extract.extract_matches_by_platform(platform: 'instagram') # or use :instagram +# {"instagram"=>{:profile=>[{:matched=>"https://instagram.com/__disco__dudehttps", "username"=>"__disco__dudehttps"}]}} + +# to extract links or data using specific regex like twitter status +matches = extract.extract_matches_by_regex(regex: SocialsRegex::Regexes::TWITTER_URL_REGEX[:status]) +# [{:matched=>"https://twitter.com/karllorey/status/1259924082067374088", "username"=>"karllorey", "tweet_id"=>"1259924082067374088"}, +# {:matched=>"https://twitter.com/karllorey12/status/12599240820673740883", "username"=>"karllorey12", "tweet_id"=>"12599240820673740883"}] + + +``` ## Development @@ -27,7 +84,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/talaatmagdyx/socials_regex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/socials_regex/blob/master/CODE_OF_CONDUCT.md). +Bug reports and pull requests are welcome on GitHub at [Contributing](https://github.com/talaatmagdyx/socials_regex/blob/master/.github/CODE_OF_CONDUCT.md). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/talaatmagdyx/socials_regex/blob/master/CODE_OF_CONDUCT.md). + +## Pull Request +Please read [Contributing](https://github.com/talaatmagdyx/socials_regex/blob/master/.github/PULL_REQUEST_TEMPLATE.md) ## License @@ -35,4 +95,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## Code of Conduct -Everyone interacting in the SocialsRegex project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/socials_regex/blob/master/.github/CODE_OF_CONDUCT.md). +Everyone interacting in the SocialsRegex project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/talaatmagdyx/socials_regex/blob/master/.github/CODE_OF_CONDUCT.md). diff --git a/lib/socials_regex/platforms.rb b/lib/socials_regex/platforms.rb index 0fc6d86..8b4a99d 100644 --- a/lib/socials_regex/platforms.rb +++ b/lib/socials_regex/platforms.rb @@ -233,5 +233,9 @@ class Regexes def self.match?(input_str:, regex:) input_str.match(regex) ? true : false end + + def self.all + Regexes.constants + end end end diff --git a/sig/socials_regex/regexes.rbs b/sig/socials_regex/regexes.rbs index 5e6a607..1239e7a 100644 --- a/sig/socials_regex/regexes.rbs +++ b/sig/socials_regex/regexes.rbs @@ -24,6 +24,8 @@ module SocialsRegex YELP_URL_REGEX: Hash[Symbol, Regexp] YOUTUBE_URL_REGEX: Hash[Symbol, Regexp] + def self.all: -> Array[Symbol] + def self.match?: (input_str: string, regex: Regexp)-> bool end end